1 | #ifndef SH_PTHREAD_H
|
---|
2 | #define SH_PTHREAD_H
|
---|
3 |
|
---|
4 | #ifdef HAVE_PTHREAD
|
---|
5 |
|
---|
6 | #include <pthread.h>
|
---|
7 | #define SH_MUTEX(M) pthread_mutex_t M
|
---|
8 | #define SH_MUTEX_INIT(M,I) pthread_mutex_t M = I
|
---|
9 | #define SH_MUTEX_STATIC(M,I) static pthread_mutex_t M = I
|
---|
10 | #define SH_MUTEX_EXTERN(M) extern pthread_mutex_t M
|
---|
11 |
|
---|
12 | #define SH_MUTEX_LOCK(M) \
|
---|
13 | do { \
|
---|
14 | int oldtype; \
|
---|
15 | pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype); \
|
---|
16 | pthread_cleanup_push(pthread_mutex_unlock, (void *) &(M)); \
|
---|
17 | pthread_mutex_lock(&(M))
|
---|
18 |
|
---|
19 |
|
---|
20 | #define SH_MUTEX_UNLOCK(M,C) \
|
---|
21 | pthread_cleanup_pop(1); \
|
---|
22 | pthread_setcanceltype(oldtype, NULL); \
|
---|
23 | } while (0)
|
---|
24 |
|
---|
25 | #define SH_MUTEX_LOCK_UNSAFE(M) pthread_mutex_lock(&(M))
|
---|
26 | #define SH_MUTEX_UNLOCK_UNSAFE(M) pthread_mutex_unlock(&(M))
|
---|
27 |
|
---|
28 | #else
|
---|
29 |
|
---|
30 | #define SH_MUTEX(M) void *SH_MUTEX_DUMMY_ ## M
|
---|
31 | #define SH_MUTEX_INIT(M,I) extern void *SH_MUTEX_DUMMY_ ## M
|
---|
32 | #define SH_MUTEX_STATIC(M,I) extern void *SH_MUTEX_DUMMY_ ## M
|
---|
33 | #define SH_MUTEX_EXTERN(M) extern void *SH_MUTEX_DUMMY_ ## M
|
---|
34 | #define SH_MUTEX_LOCK(M) ((void)0)
|
---|
35 | #define SH_MUTEX_UNLOCK(M) ((void)0)
|
---|
36 | #define SH_MUTEX_LOCK_UNSAFE(M) ((void)0)
|
---|
37 | #define SH_MUTEX_UNLOCK_UNSAFE(M) ((void)0)
|
---|
38 |
|
---|
39 | /* #ifdef HAVE_PTHREAD */
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | /* #ifndef SH_PTHREAD_H */
|
---|
43 | #endif
|
---|