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