You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.8 KiB

2 months ago
  1. /* thread.h (pthread emulation for Windows) */
  2. /***********************************************************************
  3. * This code is part of GLPK (GNU Linear Programming Kit).
  4. *
  5. * Copyright (C) 2011-2017, Heinrich Schuchardt <xypron.glpk@gmx.de>
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
  15. * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. ***********************************************************************/
  19. #ifndef THREAD_H
  20. #define THREAD_H 1
  21. #ifdef HAVE_CONFIG_H
  22. #include "config.h"
  23. #endif // HAVE_CONFIG_H
  24. #ifdef __WOE__
  25. #include <windows.h>
  26. typedef CRITICAL_SECTION pthread_mutex_t;
  27. typedef HANDLE pthread_t;
  28. // @todo The return type of routine C is "DWORD" for Windows and
  29. // "void *" for Posix.
  30. #define pthread_create(A,B,C,D) \
  31. (int)((*A = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)&C,D,0,NULL))==NULL)
  32. #define pthread_exit(A) ExitThread(0)
  33. #define pthread_mutex_destroy(A) DeleteCriticalSection(A)
  34. #define pthread_mutex_init(A,B) (InitializeCriticalSection(A),0)
  35. #define pthread_mutex_lock(A) (EnterCriticalSection(A),0)
  36. #define pthread_mutex_unlock(A) (LeaveCriticalSection(A),0)
  37. #define pthread_self() GetCurrentThreadId()
  38. #define pthread_join(A, B) \
  39. (WaitForSingleObject(A, INFINITE),CloseHandle(A),0)
  40. #else
  41. #include <pthread.h>
  42. #endif
  43. #endif // THREAD_H