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>
23 #include <sys/lockmgr.h>
28 #define RX_ENABLE_LOCKS 1
29 #define AFS_GLOBAL_RXLOCK_KERNEL
31 typedef int afs_kcondvar_t;
34 #if defined(NULL_LOCKS)
39 #define MUTEX_INIT(a,b,c,d) \
43 #define MUTEX_DESTROY(a) \
45 (a)->owner = (struct proc *)-1; \
47 #define MUTEX_ENTER(a) \
49 osi_Assert((a)->owner == 0); \
50 (a)->owner = curproc; \
52 #define MUTEX_TRYENTER(a) \
53 ( osi_Assert((a)->owner == 0), (a)->owner = curproc, 1)
54 #define MUTEX_EXIT(a) \
56 osi_Assert((a)->owner == curproc); \
61 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == curproc)
63 #elif defined(AFS_FBSD70_ENV) /* dunno about 6.x */
65 typedef struct mtx afs_kmutex_t;
67 #if defined(AFS_FBSD80_ENV) && defined(WITNESS)
68 #define WITCLEAR_MTX(a) \
69 do { memset((a), 0, sizeof(struct mtx)); } while(0);
71 #define WITCLEAR_MTX(a) {}
74 #define MUTEX_INIT(a,b,c,d) \
77 mtx_init((a), (b), 0 /* type defaults to name */, MTX_DEF | MTX_DUPOK); \
80 #define MUTEX_DESTROY(a) \
85 #define MUTEX_ENTER(a) \
90 #define MUTEX_TRYENTER(a) \
93 #define MUTEX_EXIT(a) \
99 #define MUTEX_ISMINE(a) \
106 struct thread *owner;
110 #define MUTEX_INIT(a,b,c,d) \
112 lockinit(&(a)->lock,PSOCK, "afs rx mutex", 0, 0); \
115 #define MUTEX_DESTROY(a) \
117 (a)->owner = (struct proc *)-1; \
119 #define MUTEX_ENTER(a) \
121 lockmgr(&(a)->lock, LK_EXCLUSIVE, 0, curthread); \
122 osi_Assert((a)->owner == 0); \
123 (a)->owner = curthread; \
125 #define MUTEX_TRYENTER(a) \
126 ( lockmgr(&(a)->lock, LK_EXCLUSIVE|LK_NOWAIT, 0, curthread) ? 0 : ((a)->owner = curthread, 1) )
127 #define xMUTEX_TRYENTER(a) \
128 ( osi_Assert((a)->owner == 0), (a)->owner = curthread, 1)
129 #define MUTEX_EXIT(a) \
131 osi_Assert((a)->owner == curthread); \
133 lockmgr(&(a)->lock, LK_RELEASE, 0, curthread); \
137 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == curthread)
141 #undef osirx_AssertMine
142 extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
146 * Condition variables
148 * In Digital Unix (OSF/1), we use something akin to the ancient sleep/wakeup
149 * mechanism. The condition variable itself plays no role; we just use its
150 * address as a convenient unique number.
152 #define CV_INIT(cv,a,b,c)
153 #define CV_DESTROY(cv)
155 #if defined(AFS_FBSD70_ENV)
157 #define CV_WAIT(cv, lck) { \
158 int isGlockOwner = ISAFS_GLOCK(); \
159 if (isGlockOwner) AFS_GUNLOCK(); \
160 msleep(cv, lck, PSOCK, "afs_rx_cv_wait", 0); \
161 if (isGlockOwner) AFS_GLOCK(); \
164 #define CV_TIMEDWAIT(cv,lck,t) { \
165 int isGlockOwner = ISAFS_GLOCK(); \
166 if (isGlockOwner) AFS_GUNLOCK(); \
167 msleep(cv, lck, PSOCK, "afs_rx_cv_timedwait", t); \
168 if (isGlockOwner) AFS_GLOCK(); \
170 #else /* !AFS_FBSD70_ENV */
171 #define CV_WAIT(cv, lck) { \
172 int isGlockOwner = ISAFS_GLOCK(); \
173 if (isGlockOwner) AFS_GUNLOCK(); \
175 tsleep(cv, PSOCK, "afs_rx_cv_wait", 0); \
176 if (isGlockOwner) AFS_GLOCK(); \
180 #define CV_TIMEDWAIT(cv,lck,t) { \
181 int isGlockOwner = ISAFS_GLOCK(); \
182 if (isGlockOwner) AFS_GUNLOCK(); \
184 tsleep(cv, PSOCK, "afs_rx_cv_timedwait", t); \
185 if (isGlockOwner) AFS_GLOCK(); \
188 #endif /* AFS_FBSD80_ENV */
190 #define CV_SIGNAL(cv) wakeup_one(cv)
191 #define CV_BROADCAST(cv) wakeup(cv)
193 /* #define osi_rxWakeup(cv) wakeup(cv) */
196 #endif /* _RX_KMUTEX_H_ */