[130] | 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 |
|
---|
[132] | 25 | #define SH_MUTEX_LOCK_UNSAFE(M) pthread_mutex_lock(&(M))
|
---|
| 26 | #define SH_MUTEX_UNLOCK_UNSAFE(M) pthread_mutex_unlock(&(M))
|
---|
[130] | 27 |
|
---|
[133] | 28 | /*
|
---|
| 29 | * ---- Global mutexes ----
|
---|
| 30 | */
|
---|
| 31 | SH_MUTEX_EXTERN(mutex_skey);
|
---|
[134] | 32 | SH_MUTEX_EXTERN(mutex_resolv);
|
---|
| 33 | SH_MUTEX_EXTERN(mutex_pwent);
|
---|
[133] | 34 |
|
---|
[134] | 35 | /*
|
---|
| 36 | * ---- Initialize thread-specific conversion area ----
|
---|
| 37 | */
|
---|
| 38 | extern int sh_g_thread();
|
---|
| 39 |
|
---|
[130] | 40 | #else
|
---|
| 41 |
|
---|
| 42 | #define SH_MUTEX(M) void *SH_MUTEX_DUMMY_ ## M
|
---|
| 43 | #define SH_MUTEX_INIT(M,I) extern void *SH_MUTEX_DUMMY_ ## M
|
---|
| 44 | #define SH_MUTEX_STATIC(M,I) extern void *SH_MUTEX_DUMMY_ ## M
|
---|
| 45 | #define SH_MUTEX_EXTERN(M) extern void *SH_MUTEX_DUMMY_ ## M
|
---|
| 46 | #define SH_MUTEX_LOCK(M) ((void)0)
|
---|
| 47 | #define SH_MUTEX_UNLOCK(M) ((void)0)
|
---|
[132] | 48 | #define SH_MUTEX_LOCK_UNSAFE(M) ((void)0)
|
---|
| 49 | #define SH_MUTEX_UNLOCK_UNSAFE(M) ((void)0)
|
---|
[130] | 50 |
|
---|
| 51 | /* #ifdef HAVE_PTHREAD */
|
---|
| 52 | #endif
|
---|
| 53 |
|
---|
| 54 | /* #ifndef SH_PTHREAD_H */
|
---|
| 55 | #endif
|
---|