rx: Constify rx_opaque_populate
[openafs.git] / src / rx / rx_pthread.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /* rx_pthread.h defines the lock and cv primitives required for a thread
11  * safe user mode rx. The current implemenation is only tested on Solaris.
12  */
13
14 #ifndef RX_PTHREAD_H
15 #define RX_PTHREAD_H
16
17 #ifndef RX_ENABLE_LOCKS
18 #define RX_ENABLE_LOCKS 1
19 #endif
20
21 /* This turns out to be necessary even for fine grain locking. */
22 #ifndef AFS_GLOBAL_RXLOCK_KERNEL
23 #define AFS_GLOBAL_RXLOCK_KERNEL 1
24 #endif
25
26 /* Block signals to child threads. */
27 #include <afs/pthread_nosigs.h>
28
29 #ifdef AFS_NT40_ENV
30 #include <wtypes.h>
31 #include <winbase.h>
32 #include <winsock2.h>
33 #include <pthread.h>
34
35 typedef pthread_mutex_t afs_kmutex_t;
36 typedef pthread_cond_t afs_kcondvar_t;
37 #ifdef  RX_ENABLE_LOCKS
38 #define MUTEX_ISMINE(l) (pthread_mutex_trylock(l) == EDEADLK)
39 #else
40 #define MUTEX_ISMINE(l) (1)
41 #endif
42
43 #define pthread_yield() Sleep(0)
44
45 #else /* AFS_NT40_ENV */
46
47 #include <pthread.h>
48 typedef pthread_mutex_t afs_kmutex_t;
49 typedef pthread_cond_t afs_kcondvar_t;
50
51 #if !defined(pthread_yield) && defined(AFS_SUN5_ENV)
52 #define pthread_yield() thr_yield()
53 #endif
54 #if !defined(pthread_yield) && !defined(AFS_AIX_ENV)
55 #define pthread_yield() sleep(0)
56 #endif
57 #if !defined(pthread_yield) && (_XOPEN_SOURCE + 0) >= 500
58 #define pthread_yield() sched_yield()
59 #endif
60
61
62 #ifndef MUTEX_ISMINE
63 /* Only used for debugging. */
64 #ifdef AFS_SUN5_ENV
65 /* synch.h says mutex_t and pthread_mutex_t are always the same */
66 #include <synch.h>
67 #define MUTEX_ISMINE(l) MUTEX_HELD((mutex_t *) l)
68 #else /* AFS_SUN5_ENV */
69 #define MUTEX_ISMINE(l) (1)
70 #endif /* AFS_SUN5_ENV */
71 #endif /* !MUTEX_ISMINE */
72 #endif /* AFS_NT40_ENV */
73
74 extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
75
76 #ifdef AFS_PTHREAD_ENV
77 #ifdef MUTEX_INIT
78 #undef MUTEX_INIT
79 #endif
80 #define MUTEX_INIT(a, b, c, d) osi_Assert(pthread_mutex_init(a, NULL) == 0)
81
82 #ifdef MUTEX_DESTROY
83 #undef MUTEX_DESTROY
84 #endif
85 #define MUTEX_DESTROY(l) osi_Assert(pthread_mutex_destroy(l) == 0)
86
87 #ifdef MUTEX_ENTER
88 #undef MUTEX_ENTER
89 #endif
90 #define MUTEX_ENTER(l) osi_Assert(pthread_mutex_lock(l) == 0)
91
92 #ifdef MUTEX_TRYENTER
93 #undef MUTEX_TRYENTER
94 #endif
95 #define MUTEX_TRYENTER(l) pthread_mutex_trylock(l) ? 0 : 1
96
97 #ifdef MUTEX_EXIT
98 #undef MUTEX_EXIT
99 #endif
100 #define MUTEX_EXIT(l) osi_Assert(pthread_mutex_unlock(l) == 0)
101
102 #ifdef CV_INIT
103 #undef CV_INIT
104 #endif
105 #define CV_INIT(cv, a, b, c) osi_Assert(pthread_cond_init(cv, NULL) == 0)
106
107 #ifdef CV_DESTROY
108 #undef CV_DESTROY
109 #endif
110 #define CV_DESTROY(cv) osi_Assert(pthread_cond_destroy(cv) == 0)
111
112 #ifdef CV_WAIT
113 #undef CV_WAIT
114 #endif
115 #define CV_WAIT(cv, l) osi_Assert(pthread_cond_wait(cv, l) == 0)
116
117 #ifdef CV_TIMEDWAIT
118 #undef CV_TIMEDWAIT
119 #endif
120 #define CV_TIMEDWAIT(cv, l, t) pthread_cond_timedwait(cv, l, t)
121
122 #ifdef CV_SIGNAL
123 #undef CV_SIGNAL
124 #endif
125 #define CV_SIGNAL(cv) osi_Assert(pthread_cond_signal(cv) == 0)
126
127 #ifdef CV_BROADCAST
128 #undef CV_BROADCAST
129 #endif
130 #define CV_BROADCAST(cv) osi_Assert(pthread_cond_broadcast(cv) == 0)
131
132 #endif /* AFS_PTHREAD_ENV */
133
134
135 #endif /* RX_PTHREAD_H */