source: trunk/include/sh_pthread.h @ 133

Last change on this file since 133 was 133, checked in by rainer, 12 years ago

Reentrant checksum/hash functions.

File size: 1.5 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);
32
33#else
34
35#define SH_MUTEX(M)                             void *SH_MUTEX_DUMMY_ ## M
36#define SH_MUTEX_INIT(M,I)                      extern void *SH_MUTEX_DUMMY_ ## M
37#define SH_MUTEX_STATIC(M,I)                    extern void *SH_MUTEX_DUMMY_ ## M
38#define SH_MUTEX_EXTERN(M)                      extern void *SH_MUTEX_DUMMY_ ## M
39#define SH_MUTEX_LOCK(M)                        ((void)0)
40#define SH_MUTEX_UNLOCK(M)                      ((void)0)
41#define SH_MUTEX_LOCK_UNSAFE(M)                 ((void)0)
42#define SH_MUTEX_UNLOCK_UNSAFE(M)               ((void)0)
43
44/* #ifdef HAVE_PTHREAD */
45#endif
46
47/* #ifndef SH_PTHREAD_H */
48#endif
Note: See TracBrowser for help on using the repository browser.