semaphore.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. Copyright (c) 2011-2016 mingw-w64 project
  3. Permission is hereby granted, free of charge, to any person obtaining a
  4. copy of this software and associated documentation files (the "Software"),
  5. to deal in the Software without restriction, including without limitation
  6. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  7. and/or sell copies of the Software, and to permit persons to whom the
  8. Software is furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  16. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. DEALINGS IN THE SOFTWARE.
  18. */
  19. #ifndef WIN_PTHREADS_SEMAPHORE_H
  20. #define WIN_PTHREADS_SEMAPHORE_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #if defined(IN_WINPTHREAD)
  25. # if defined(DLL_EXPORT) && !defined(WINPTHREAD_EXPORT_ALL_DEBUG)
  26. # define WINPTHREAD_SEMA_API __declspec(dllexport) /* building the DLL */
  27. # else
  28. # define WINPTHREAD_SEMA_API /* building the static library */
  29. # endif
  30. #else
  31. # if defined(WINPTHREADS_USE_DLLIMPORT)
  32. # define WINPTHREAD_SEMA_API __declspec(dllimport) /* user wants explicit `dllimport` */
  33. # else
  34. # define WINPTHREAD_SEMA_API /* the default; auto imported in case of DLL */
  35. # endif
  36. #endif
  37. /* Set this to 0 to disable it */
  38. #define USE_SEM_CriticalSection_SpinCount 100
  39. #define SEM_VALUE_MAX INT_MAX
  40. #ifndef _MODE_T_
  41. #define _MODE_T_
  42. typedef unsigned short mode_t;
  43. #endif
  44. typedef void *sem_t;
  45. #define SEM_FAILED NULL
  46. int WINPTHREAD_SEMA_API sem_init(sem_t * sem, int pshared, unsigned int value);
  47. int WINPTHREAD_SEMA_API sem_destroy(sem_t *sem);
  48. int WINPTHREAD_SEMA_API sem_trywait(sem_t *sem);
  49. int WINPTHREAD_SEMA_API sem_wait(sem_t *sem);
  50. int WINPTHREAD_SEMA_API sem_timedwait(sem_t * sem, const struct timespec *t);
  51. int WINPTHREAD_SEMA_API sem_post(sem_t *sem);
  52. int WINPTHREAD_SEMA_API sem_post_multiple(sem_t *sem, int count);
  53. /* yes, it returns a semaphore (or SEM_FAILED) */
  54. sem_t * WINPTHREAD_SEMA_API sem_open(const char * name, int oflag, mode_t mode, unsigned int value);
  55. int WINPTHREAD_SEMA_API sem_close(sem_t * sem);
  56. int WINPTHREAD_SEMA_API sem_unlink(const char * name);
  57. int WINPTHREAD_SEMA_API sem_getvalue(sem_t * sem, int * sval);
  58. #ifdef __cplusplus
  59. }
  60. #endif
  61. #endif /* WIN_PTHREADS_SEMAPHORE_H */