| 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 | #include <sys/timeb.h> |
| 27 | #include "pthread_compat.h" |
| 28 | |
| 29 | #ifdef __cplusplus |
| 30 | extern "C" { |
| 31 | #endif |
| 32 | |
| 33 | #define SEM_VALUE_MAX INT_MAX |
| 34 | |
| 35 | typedef void		*sem_t; |
| 36 | |
| 37 | #define SEM_FAILED 		NULL |
| 38 | |
| 39 | WINPTHREAD_API int sem_init(sem_t * sem, int pshared, unsigned int value); |
| 40 | |
| 41 | WINPTHREAD_API int sem_destroy(sem_t *sem); |
| 42 | |
| 43 | WINPTHREAD_API int sem_trywait(sem_t *sem); |
| 44 | |
| 45 | WINPTHREAD_API int sem_wait(sem_t *sem); |
| 46 | |
| 47 | WINPTHREAD_API int sem_timedwait32(sem_t * sem, const struct _timespec32 *t); |
| 48 | WINPTHREAD_API int sem_timedwait64(sem_t * sem, const struct _timespec64 *t); |
| 49 | WINPTHREAD_SEM_DECL int sem_timedwait(sem_t * sem, const struct timespec *t) |
| 50 | { |
| 51 | #if WINPTHREADS_TIME_BITS == 32 |
| 52 | return sem_timedwait32 (sem, (const struct _timespec32 *) t); |
| 53 | #else |
| 54 | return sem_timedwait64 (sem, (const struct _timespec64 *) t); |
| 55 | #endif |
| 56 | } |
| 57 | |
| 58 | WINPTHREAD_API int sem_post(sem_t *sem); |
| 59 | |
| 60 | WINPTHREAD_API int sem_post_multiple(sem_t *sem, int count); |
| 61 | |
| 62 | /* yes, it returns a semaphore (or SEM_FAILED) */ |
| 63 | WINPTHREAD_API sem_t * sem_open(const char * name, int oflag, mode_t mode, unsigned int value); |
| 64 | |
| 65 | WINPTHREAD_API int sem_close(sem_t * sem); |
| 66 | |
| 67 | WINPTHREAD_API int sem_unlink(const char * name); |
| 68 | |
| 69 | WINPTHREAD_API int sem_getvalue(sem_t * sem, int * sval); |
| 70 | |
| 71 | #ifdef __cplusplus |
| 72 | } |
| 73 | #endif |
| 74 | |
| 75 | #endif /* WIN_PTHREADS_SEMAPHORE_H */ |