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 #define RX_ENABLE_LOCKS 1
24 #define AFS_GLOBAL_RXLOCK_KERNEL
29 * In Digital Unix (OSF/1), we use something akin to the ancient sleep/wakeup
30 * mechanism. The condition variable itself plays no role; we just use its
31 * address as a convenient unique number.
33 #define CV_INIT(cv,a,b,c)
34 #define CV_DESTROY(cv)
35 #define CV_WAIT(cv, lck) { \
36 int isGlockOwner = ISAFS_GLOCK(); \
37 if (isGlockOwner) AFS_GUNLOCK(); \
39 tsleep(cv, PSOCK, "afs_rx_cv_wait", 0); \
40 if (isGlockOwner) AFS_GLOCK(); \
44 #define CV_TIMEDWAIT(cv,lck,t) { \
45 int isGlockOwner = ISAFS_GLOCK(); \
46 if (isGlockOwner) AFS_GUNLOCK(); \
48 tsleep(cv, PSOCK, "afs_rx_cv_timedwait", t); \
49 if (isGlockOwner) AFS_GLOCK(); \
52 #define CV_SIGNAL(cv) wakeup_one(cv)
53 #define CV_BROADCAST(cv) wakeup(cv)
55 /* #define osi_rxWakeup(cv) wakeup(cv) */
56 typedef int afs_kcondvar_t;
64 #define MUTEX_INIT(a,b,c,d) \
68 #define MUTEX_DESTROY(a) \
70 (a)->owner = (struct proc *)-1; \
72 #define MUTEX_ENTER(a) \
74 osi_Assert((a)->owner == 0); \
75 (a)->owner = curproc; \
77 #define MUTEX_TRYENTER(a) \
78 ( osi_Assert((a)->owner == 0), (a)->owner = curproc, 1)
79 #define MUTEX_EXIT(a) \
81 osi_Assert((a)->owner == curproc); \
86 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == curproc)
96 #define MUTEX_INIT(a,b,c,d) \
98 lockinit(&(a)->lock,PSOCK, "afs rx mutex", 0, 0); \
101 #define MUTEX_DESTROY(a) \
103 (a)->owner = (struct proc *)-1; \
105 #define MUTEX_ENTER(a) \
107 lockmgr(&(a)->lock, LK_EXCLUSIVE, 0, curproc); \
108 osi_Assert((a)->owner == 0); \
109 (a)->owner = curproc; \
111 #define MUTEX_TRYENTER(a) \
112 ( lockmgr(&(a)->lock, LK_EXCLUSIVE|LK_NOWAIT, 0, curproc) ? 0 : ((a)->owner = curproc, 1) )
113 #define xMUTEX_TRYENTER(a) \
114 ( osi_Assert((a)->owner == 0), (a)->owner = curproc, 1)
115 #define MUTEX_EXIT(a) \
117 osi_Assert((a)->owner == curproc); \
119 lockmgr(&(a)->lock, LK_RELEASE, 0, curproc); \
123 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == curproc)
126 struct simplelock lock;
131 #define MUTEX_INIT(a,b,c,d) \
133 simple_lock_init(&(a)->lock); \
136 #define MUTEX_DESTROY(a) \
138 (a)->owner = (struct proc *)-1; \
140 #define MUTEX_ENTER(a) \
142 simple_lock(&(a)->lock); \
143 osi_Assert((a)->owner == 0); \
144 (a)->owner = curproc; \
146 #define MUTEX_TRYENTER(a) \
147 ( simple_lock_try(&(a)->lock) ? 0 : ((a)->owner = curproc, 1) )
148 #define MUTEX_EXIT(a) \
150 osi_Assert((a)->owner == curproc); \
152 simple_unlock(&(a)->lock); \
156 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == curproc)
161 #undef osirx_AssertMine
162 extern void osirx_AssertMine(afs_kmutex_t *lockaddr, char *msg);
164 #endif /* _RX_KMUTEX_H_ */