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