source: trunk/include/sh_pthread.h@ 137

Last change on this file since 137 was 134, checked in by rainer, 17 years ago

More thread-safety changes.

File size: 1.6 KB
Line 
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/*
29 * ---- Global mutexes ----
30 */
31SH_MUTEX_EXTERN(mutex_skey);
32SH_MUTEX_EXTERN(mutex_resolv);
33SH_MUTEX_EXTERN(mutex_pwent);
34
35/*
36 * ---- Initialize thread-specific conversion area ----
37 */
38extern int sh_g_thread();
39
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)
48#define SH_MUTEX_LOCK_UNSAFE(M) ((void)0)
49#define SH_MUTEX_UNLOCK_UNSAFE(M) ((void)0)
50
51/* #ifdef HAVE_PTHREAD */
52#endif
53
54/* #ifndef SH_PTHREAD_H */
55#endif
Note: See TracBrowser for help on using the repository browser.