semaphore.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Module: semaphore.h
  3. *
  4. * Purpose:
  5. * Semaphores aren't actually part of the PThreads standard.
  6. * They are defined by the POSIX Standard:
  7. *
  8. * POSIX 1003.1b-1993 (POSIX.1b)
  9. *
  10. * --------------------------------------------------------------------------
  11. *
  12. * Pthreads-win32 - POSIX Threads Library for Win32
  13. * Copyright(C) 1998 John E. Bossom
  14. * Copyright(C) 1999,2005 Pthreads-win32 contributors
  15. *
  16. * Contact Email: rpj@callisto.canberra.edu.au
  17. *
  18. * The current list of contributors is contained
  19. * in the file CONTRIBUTORS included with the source
  20. * code distribution. The list can also be seen at the
  21. * following World Wide Web location:
  22. * http://sources.redhat.com/pthreads-win32/contributors.html
  23. *
  24. * This library is free software; you can redistribute it and/or
  25. * modify it under the terms of the GNU Lesser General Public
  26. * License as published by the Free Software Foundation; either
  27. * version 2 of the License, or (at your option) any later version.
  28. *
  29. * This library is distributed in the hope that it will be useful,
  30. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  32. * Lesser General Public License for more details.
  33. *
  34. * You should have received a copy of the GNU Lesser General Public
  35. * License along with this library in the file COPYING.LIB;
  36. * if not, write to the Free Software Foundation, Inc.,
  37. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  38. */
  39. #if !defined( SEMAPHORE_H )
  40. #define SEMAPHORE_H
  41. #undef PTW32_SEMAPHORE_LEVEL
  42. #if defined(_POSIX_SOURCE)
  43. #define PTW32_SEMAPHORE_LEVEL 0
  44. /* Early POSIX */
  45. #endif
  46. #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
  47. #undef PTW32_SEMAPHORE_LEVEL
  48. #define PTW32_SEMAPHORE_LEVEL 1
  49. /* Include 1b, 1c and 1d */
  50. #endif
  51. #if defined(INCLUDE_NP)
  52. #undef PTW32_SEMAPHORE_LEVEL
  53. #define PTW32_SEMAPHORE_LEVEL 2
  54. /* Include Non-Portable extensions */
  55. #endif
  56. #define PTW32_SEMAPHORE_LEVEL_MAX 3
  57. #if !defined(PTW32_SEMAPHORE_LEVEL)
  58. #define PTW32_SEMAPHORE_LEVEL PTW32_SEMAPHORE_LEVEL_MAX
  59. /* Include everything */
  60. #endif
  61. #if defined(__GNUC__) && ! defined (__declspec)
  62. # error Please upgrade your GNU compiler to one that supports __declspec.
  63. #endif
  64. /*
  65. * When building the library, you should define PTW32_BUILD so that
  66. * the variables/functions are exported correctly. When using the library,
  67. * do NOT define PTW32_BUILD, and then the variables/functions will
  68. * be imported correctly.
  69. */
  70. #if !defined(PTW32_STATIC_LIB)
  71. # if defined(PTW32_BUILD)
  72. # define PTW32_DLLPORT __declspec (dllexport)
  73. # else
  74. # define PTW32_DLLPORT __declspec (dllimport)
  75. # endif
  76. #else
  77. # define PTW32_DLLPORT
  78. #endif
  79. /*
  80. * This is a duplicate of what is in the autoconf config.h,
  81. * which is only used when building the pthread-win32 libraries.
  82. */
  83. #if !defined(PTW32_CONFIG_H)
  84. # if defined(WINCE)
  85. # define NEED_ERRNO
  86. # define NEED_SEM
  87. # endif
  88. # if defined(__MINGW64__)
  89. # define HAVE_STRUCT_TIMESPEC
  90. # define HAVE_MODE_T
  91. # elif defined(_UWIN) || defined(__MINGW32__)
  92. # define HAVE_MODE_T
  93. # endif
  94. #endif
  95. /*
  96. *
  97. */
  98. #if PTW32_SEMAPHORE_LEVEL >= PTW32_SEMAPHORE_LEVEL_MAX
  99. #if defined(NEED_ERRNO)
  100. #include "need_errno.h"
  101. #else
  102. #include <errno.h>
  103. #endif
  104. #endif /* PTW32_SEMAPHORE_LEVEL >= PTW32_SEMAPHORE_LEVEL_MAX */
  105. #define _POSIX_SEMAPHORES
  106. #if defined(__cplusplus)
  107. extern "C"
  108. {
  109. #endif /* __cplusplus */
  110. #if !defined(HAVE_MODE_T)
  111. typedef unsigned int mode_t;
  112. #endif
  113. typedef struct sem_t_ * sem_t;
  114. PTW32_DLLPORT int __cdecl sem_init (sem_t * sem,
  115. int pshared,
  116. unsigned int value);
  117. PTW32_DLLPORT int __cdecl sem_destroy (sem_t * sem);
  118. PTW32_DLLPORT int __cdecl sem_trywait (sem_t * sem);
  119. PTW32_DLLPORT int __cdecl sem_wait (sem_t * sem);
  120. PTW32_DLLPORT int __cdecl sem_timedwait (sem_t * sem,
  121. const struct timespec * abstime);
  122. PTW32_DLLPORT int __cdecl sem_post (sem_t * sem);
  123. PTW32_DLLPORT int __cdecl sem_post_multiple (sem_t * sem,
  124. int count);
  125. PTW32_DLLPORT int __cdecl sem_open (const char * name,
  126. int oflag,
  127. mode_t mode,
  128. unsigned int value);
  129. PTW32_DLLPORT int __cdecl sem_close (sem_t * sem);
  130. PTW32_DLLPORT int __cdecl sem_unlink (const char * name);
  131. PTW32_DLLPORT int __cdecl sem_getvalue (sem_t * sem,
  132. int * sval);
  133. #if defined(__cplusplus)
  134. } /* End of extern "C" */
  135. #endif /* __cplusplus */
  136. #undef PTW32_SEMAPHORE_LEVEL
  137. #undef PTW32_SEMAPHORE_LEVEL_MAX
  138. #endif /* !SEMAPHORE_H */