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 * Based to the degree possible on FreeBSD implementation (which is by
14 * Garrett Wollman (?) and Jim Rees). I couldn't rework it as I did for
15 * FreeBSD, because NetBSD doesn't have anything like FreeBSD's new
16 * locking primitives. So anyway, these are potentially heavier locks than
17 * the *ahem* locking Jim had in the OpenBSD port, although it looks as
18 * if struct lock is evolving into an adaptive mutex implementation (see
19 * LOCK(9)), which should be reasonable for the code we have today. The
20 * available optimization would be to replace such a lock with a simple_lock
21 * any place we only consider the current CPU, and could not sleep
30 /* You can't have AFS_GLOBAL_SUNLOCK and not RX_ENABLE_LOCKS */
31 #define RX_ENABLE_LOCKS 1
32 #define AFS_GLOBAL_RXLOCK_KERNEL
37 * In Digital Unix (OSF/1), we use something akin to the ancient sleep/wakeup
38 * mechanism. The condition variable itself plays no role; we just use its
39 * address as a convenient unique number. NetBSD has some improvements in
40 * its versions of these mechanisms.
42 #define CV_INIT(cv, a, b, c)
43 #define CV_DESTROY(cv)
44 #define CV_WAIT(cv, lck) { \
45 struct simplelock slock = SIMPLELOCK_INITIALIZER; \
46 simple_lock(&slock); \
47 int glocked = ISAFS_GLOCK(); \
51 ltsleep(cv, PSOCK, "afs_rx_cv_wait", 0, &slock); \
55 simple_unlock(&slock); \
58 #define CV_TIMEDWAIT(cv, lck, t) { \
59 struct simplelock slock = SIMPLELOCK_INITIALIZER; \
60 simple_lock(&slock); \
61 int glocked = ISAFS_GLOCK(); \
65 tsleep(cv, PSOCK, "afs_rx_cv_timedwait", t, &slock); \
69 simple_unlock(&slock); \
72 #define CV_SIGNAL(cv) wakeup_one(cv)
73 #define CV_BROADCAST(cv) wakeup(cv)
75 /* #define osi_rxWakeup(cv) wakeup(cv) */
76 typedef int afs_kcondvar_t;
83 #define MUTEX_INIT(a,b,c,d) \
85 lockinit(&(a)->lock, PSOCK, "afs rx mutex", 0, 0); \
88 #define MUTEX_DESTROY(a) \
90 (a)->owner = (struct lwp *)-1; \
93 #if defined(LOCKDEBUG)
94 #define MUTEX_ENTER(a) \
96 _lockmgr(&(a)->lock, LK_EXCLUSIVE, 0, __FILE__, __LINE__); \
97 osi_Assert((a)->owner == 0); \
98 (a)->owner = curlwp; \
100 #define MUTEX_TRYENTER(a) \
101 ( _lockmgr(&(a)->lock, LK_EXCLUSIVE | LK_NOWAIT, 0, __FILE__, __LINE__) ? 0 \
102 : ((a)->owner = curlwp, 1) )
103 #define MUTEX_EXIT(a) \
105 osi_Assert((a)->owner == curlwp); \
107 _lockmgr(&(a)->lock, LK_RELEASE, 0, __FILE__, __LINE__); \
110 #define MUTEX_ENTER(a) \
112 lockmgr(&(a)->lock, LK_EXCLUSIVE, 0); \
113 osi_Assert((a)->owner == 0); \
114 (a)->owner = curlwp; \
116 #define MUTEX_TRYENTER(a) \
117 ( lockmgr(&(a)->lock, LK_EXCLUSIVE | LK_NOWAIT, 0) ? 0 \
118 : ((a)->owner = curlwp, 1) )
119 #define MUTEX_EXIT(a) \
121 osi_Assert((a)->owner == curlwp); \
123 lockmgr(&(a)->lock, LK_RELEASE, 0); \
125 #endif /* LOCKDEBUG */
126 #define MUTEX_ISMINE(a) \
127 (lockstatus(a) == LK_EXCLUSIVE)
128 #define MUTEX_LOCKED(a) \
129 (lockstatus(a) == LK_EXCLUSIVE)
131 #endif /* _RX_KMUTEX_H_ */