]> pd.if.org Git - pdclib/blob - opt/pthreads/mtx_timedlock.c
PDCLib includes with quotes, not <>.
[pdclib] / opt / pthreads / mtx_timedlock.c
1 #ifndef REGTEST
2 #define _POSIX_C_SOURCE 2008098L
3 #include <threads.h>
4 // On Mac OS X, supress system definition of struct timespec
5 #ifdef __APPLE__
6     #define _STRUCT_TIMESPEC struct timespec
7 #endif
8 #include <unistd.h>
9 #include <errno.h>
10 #include <pthread.h>
11
12 /* Can only implement if timeouts are supported.
13  *
14  * Namely, Mac OS X does not implement timeouts
15  */
16 #if defined(_POSIX_TIMEOUTS) && (_POSIX_TIMEOUTS - 200112L) >= 0L
17 int mtx_timedlock(mtx_t *restrict mtx, const struct timespec *restrict ts)
18 {
19     switch(pthread_mutex_timedlock(mtx, ts)) {
20         case 0:
21             return thrd_success;
22         case ETIMEDOUT:
23             return thrd_timeout;
24         default:
25             return thrd_error;
26     }
27 }
28 #endif
29
30 #endif
31
32 #ifdef TEST
33 #include "_PDCLIB_test.h"
34
35 int main( void )
36 {
37     return TEST_RESULTS;
38 }
39
40 #endif