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
10 /* rx_kmutex.h - mutex and condition variable macros for kernel environment.
12 * HPUX implementation.
18 #if defined(AFS_HPUX110_ENV) && defined(KERNEL)
19 /* rx fine grain locking primitives */
21 #include <sys/ksleep.h>
22 #include <sys/spinlock.h>
23 #include <sys/sem_beta.h>
24 #include <sys/errno.h>
25 #include <net/netmp.h>
27 #include "../rx/rx_kernel.h" /* For osi_Panic() */
29 #define RX_ENABLE_LOCKS 1
30 #define AFS_GLOBAL_RXLOCK_KERNEL
32 extern lock_t *rx_sleepLock;
34 /* We use beta semaphores instead of sync semaphores for Rx locks as
35 * recommended by HP labs. Sync semaphores are not supported by HP
39 #define CV_INIT(cv,a,b,c)
41 /* This is supposed to atomically drop the mutex and go to sleep
42 * and reacquire the mutex when it wakes up.
45 /* With 11.23, ksleep_prepare is not defined anywhere and
46 * ksleep_one is only referenced in a comment. sleep, get_sleep_lock
47 * and wakeup are defined in driver manuals.
48 * This works with 11.0, 11i, and 11.23
49 * Note: wakeup wakes up all threads waiting on cv.
52 #define CV_WAIT(cv, lck) \
54 get_sleep_lock((caddr_t)(cv)); \
55 if (!b_owns_sema(lck)) \
56 osi_Panic("CV_WAIT mutex not held \n"); \
58 sleep((caddr_t)(cv), PRIBIO); \
62 #define CV_SIGNAL(cv) \
64 lock_t * sleep_lock = get_sleep_lock((caddr_t)(cv)); \
65 wakeup((caddr_t)(cv)); \
66 spinunlock(sleep_lock); \
69 #define CV_BROADCAST(cv) \
71 lock_t * sleep_lock = get_sleep_lock((caddr_t)(cv)); \
72 wakeup((caddr_t)(cv)); \
73 spinunlock(sleep_lock); \
78 #define CV_WAIT(cv, lck) \
82 MP_SPINLOCK(rx_sleepLock); \
83 if (!b_owns_sema(lck)) \
84 osi_Panic("mutex not held \n"); \
86 code = ksleep_one(PCATCH | KERNEL_ADDRESS | KERN_SPINLOCK_OBJECT, \
87 (cv), rx_sleepLock, 0); \
89 if (code == EINTR) { /* lock still held */ \
90 MP_SPINUNLOCK(rx_sleepLock); \
91 } else if (code != -EINTR) { \
92 osi_Panic("ksleep_one failed: code = %d \n", code); \
95 b_psema(lck); /* grab the mutex again */ \
98 /* Wakes up a thread waiting on this condition */
99 #define CV_SIGNAL(cv) \
102 MP_SPINLOCK(rx_sleepLock); \
103 if ((code = kwakeup_one(KERNEL_ADDRESS, (cv), WAKEUP_ONE, &wo)) < 0) \
104 osi_Panic("kwakeup_one failed: code = %d \n", code); \
105 MP_SPINUNLOCK(rx_sleepLock); \
108 /* Wakes up all threads waiting on this condition */
109 #define CV_BROADCAST(cv) \
112 MP_SPINLOCK(rx_sleepLock); \
113 if ((code = kwakeup_one(KERNEL_ADDRESS, (cv), WAKEUP_ALL, &wo)) < 0) \
114 osi_Panic("kwakeup_all failed: code = %d \n", code); \
115 MP_SPINUNLOCK(rx_sleepLock); \
119 #define CV_DESTROY(a)
121 /* We now use beta semaphores for mutexes */
122 typedef b_sema_t afs_kmutex_t;
123 typedef caddr_t afs_kcondvar_t;
125 #else /* AFS_HPUX110_ENV */
127 #if defined(AFS_HPUX102_ENV)
128 #define CV_INIT(a,b,c,d)
129 #define CV_DESTROY(a)
130 #endif /* AFS_HPUX102_ENV */
131 #endif /* else AFS_HPUX110_ENV */
133 #ifdef AFS_HPUX102_ENV
135 #if defined(AFS_HPUX110_ENV)
136 #undef osirx_AssertMine
137 extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
139 #define AFS_RX_ORDER 30
141 #define MUTEX_INIT(a,b,c,d) b_initsema((a), 1, AFS_RX_ORDER, (b))
142 #define MUTEX_DESTROY(a)
144 #define MUTEX_TRYENTER(a) b_cpsema(a)
146 #ifdef AFS_HPUX1111_ENV
147 #define MUTEX_ENTER(a) \
148 ((b_owns_sema(a)) ? osi_Panic("Already Held") : b_psema(a))
149 #define MUTEX_EXIT(a) \
150 ((b_owns_sema(a)) ? b_vsema(a) : osi_Panic("mutex not held"))
152 #define MUTEX_ENTER(a) \
153 ((b_owns_sema(a)) ? (osi_Panic("Already Held"), 0) : b_psema(a))
155 #define MUTEX_EXIT(a) \
156 ((b_owns_sema(a)) ? b_vsema(a) : (osi_Panic("mutex not held"), 0))
160 #define MUTEX_ISMINE(a) b_owns_sema(a)
162 #else /* AFS_HPUX110_ENV */
164 #define osirx_AssertMine(addr, msg)
166 #define MUTEX_DESTROY(a)
167 #define MUTEX_ENTER(a)
168 #define MUTEX_TRYENTER(a) 1
169 #define MUTEX_EXIT(a)
170 #define MUTEX_INIT(a,b,c,d)
172 #endif /* else AFS_HPUX110_ENV */
173 #endif /* AFS_HPUX102_ENV */
174 #endif /* _RX_KMUTEX_H_ */