2 * Copyright 2000, International Business Machines Corporation and others.
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
11 * rx_kmutex.h - mutex and condition variable macros for kernel environment.
13 * FBSD implementation.
19 #include <sys/systm.h>
22 #include <sys/lockmgr.h>
27 #define RX_ENABLE_LOCKS 1
28 #define AFS_GLOBAL_RXLOCK_KERNEL
33 * In Digital Unix (OSF/1), we use something akin to the ancient sleep/wakeup
34 * mechanism. The condition variable itself plays no role; we just use its
35 * address as a convenient unique number.
37 #define CV_INIT(cv,a,b,c)
38 #define CV_DESTROY(cv)
39 #define CV_WAIT(cv, lck) { \
40 int isGlockOwner = ISAFS_GLOCK(); \
41 if (isGlockOwner) AFS_GUNLOCK(); \
43 tsleep(cv, PSOCK, "afs_rx_cv_wait", 0); \
44 if (isGlockOwner) AFS_GLOCK(); \
48 #define CV_TIMEDWAIT(cv,lck,t) { \
49 int isGlockOwner = ISAFS_GLOCK(); \
50 if (isGlockOwner) AFS_GUNLOCK(); \
52 tsleep(cv, PSOCK, "afs_rx_cv_timedwait", t); \
53 if (isGlockOwner) AFS_GLOCK(); \
56 #define CV_SIGNAL(cv) wakeup_one(cv)
57 #define CV_BROADCAST(cv) wakeup(cv)
59 /* #define osi_rxWakeup(cv) wakeup(cv) */
60 typedef int afs_kcondvar_t;
63 #if defined(NULL_LOCKS)
68 #define MUTEX_INIT(a,b,c,d) \
72 #define MUTEX_DESTROY(a) \
74 (a)->owner = (struct proc *)-1; \
76 #define MUTEX_ENTER(a) \
78 osi_Assert((a)->owner == 0); \
79 (a)->owner = curproc; \
81 #define MUTEX_TRYENTER(a) \
82 ( osi_Assert((a)->owner == 0), (a)->owner = curproc, 1)
83 #define MUTEX_EXIT(a) \
85 osi_Assert((a)->owner == curproc); \
90 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == curproc)
92 #elif defined(AFS_FBSD50_ENV)
99 #define MUTEX_INIT(a,b,c,d) \
101 lockinit(&(a)->lock,PSOCK, "afs rx mutex", 0, 0); \
104 #define MUTEX_DESTROY(a) \
106 (a)->owner = (struct proc *)-1; \
108 #define MUTEX_ENTER(a) \
110 lockmgr(&(a)->lock, LK_EXCLUSIVE, 0, curthread); \
111 osi_Assert((a)->owner == 0); \
112 (a)->owner = curthread; \
114 #define MUTEX_TRYENTER(a) \
115 ( lockmgr(&(a)->lock, LK_EXCLUSIVE|LK_NOWAIT, 0, curthread) ? 0 : ((a)->owner = curthread, 1) )
116 #define xMUTEX_TRYENTER(a) \
117 ( osi_Assert((a)->owner == 0), (a)->owner = curthread, 1)
118 #define MUTEX_EXIT(a) \
120 osi_Assert((a)->owner == curthread); \
122 lockmgr(&(a)->lock, LK_RELEASE, 0, curthread); \
126 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == curthread)
127 #elif defined(HEAVY_LOCKS)
134 #define MUTEX_INIT(a,b,c,d) \
136 lockinit(&(a)->lock,PSOCK, "afs rx mutex", 0, 0); \
139 #define MUTEX_DESTROY(a) \
141 (a)->owner = (struct proc *)-1; \
143 #define MUTEX_ENTER(a) \
145 lockmgr(&(a)->lock, LK_EXCLUSIVE, 0, curproc); \
146 osi_Assert((a)->owner == 0); \
147 (a)->owner = curproc; \
149 #define MUTEX_TRYENTER(a) \
150 ( lockmgr(&(a)->lock, LK_EXCLUSIVE|LK_NOWAIT, 0, curproc) ? 0 : ((a)->owner = curproc, 1) )
151 #define xMUTEX_TRYENTER(a) \
152 ( osi_Assert((a)->owner == 0), (a)->owner = curproc, 1)
153 #define MUTEX_EXIT(a) \
155 osi_Assert((a)->owner == curproc); \
157 lockmgr(&(a)->lock, LK_RELEASE, 0, curproc); \
161 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == curproc)
164 struct simplelock lock;
169 #define MUTEX_INIT(a,b,c,d) \
171 simple_lock_init(&(a)->lock); \
174 #define MUTEX_DESTROY(a) \
176 (a)->owner = (struct proc *)-1; \
178 #define MUTEX_ENTER(a) \
180 simple_lock(&(a)->lock); \
181 osi_Assert((a)->owner == 0); \
182 (a)->owner = curproc; \
184 #define MUTEX_TRYENTER(a) \
185 ( simple_lock_try(&(a)->lock) ? 0 : ((a)->owner = curproc, 1) )
186 #define MUTEX_EXIT(a) \
188 osi_Assert((a)->owner == curproc); \
190 simple_unlock(&(a)->lock); \
194 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == curproc)
198 #undef osirx_AssertMine
199 extern void osirx_AssertMine(afs_kmutex_t *lockaddr, char *msg);
201 #endif /* _RX_KMUTEX_H_ */