source: trunk/include/sh_pthread.h@ 131

Last change on this file since 131 was 130, checked in by katerina, 17 years ago

Add sh_pthread.h

File size: 1.2 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
26#else
27
28#define SH_MUTEX(M) void *SH_MUTEX_DUMMY_ ## M
29#define SH_MUTEX_INIT(M,I) extern void *SH_MUTEX_DUMMY_ ## M
30#define SH_MUTEX_STATIC(M,I) extern void *SH_MUTEX_DUMMY_ ## M
31#define SH_MUTEX_EXTERN(M) extern void *SH_MUTEX_DUMMY_ ## M
32#define SH_MUTEX_LOCK(M) ((void)0)
33#define SH_MUTEX_UNLOCK(M) ((void)0)
34
35/* #ifdef HAVE_PTHREAD */
36#endif
37
38/* #ifndef SH_PTHREAD_H */
39#endif
Note: See TracBrowser for help on using the repository browser.