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.
44 #define CV_WAIT(cv, lck) \
48 MP_SPINLOCK(rx_sleepLock); \
49 if (!b_owns_sema(lck)) \
50 osi_Panic("mutex not held \n"); \
52 code = ksleep_one(PCATCH | KERNEL_ADDRESS | KERN_SPINLOCK_OBJECT, \
53 (cv), rx_sleepLock, 0); \
55 if (code == EINTR) { /* lock still held */ \
56 MP_SPINUNLOCK(rx_sleepLock); \
57 } else if (code != -EINTR) { \
58 osi_Panic("ksleep_one failed: code = %d \n", code); \
61 b_psema(lck); /* grab the mutex again */ \
64 /* Wakes up a thread waiting on this condition */
65 #define CV_SIGNAL(cv) \
68 MP_SPINLOCK(rx_sleepLock); \
69 if ((code = kwakeup_one(KERNEL_ADDRESS, (cv), WAKEUP_ONE, &wo)) < 0) \
70 osi_Panic("kwakeup_one failed: code = %d \n", code); \
71 MP_SPINUNLOCK(rx_sleepLock); \
74 /* Wakes up all threads waiting on this condition */
75 #define CV_BROADCAST(cv) \
78 MP_SPINLOCK(rx_sleepLock); \
79 if ((code = kwakeup_one(KERNEL_ADDRESS, (cv), WAKEUP_ALL, &wo)) < 0) \
80 osi_Panic("kwakeup_all failed: code = %d \n", code); \
81 MP_SPINUNLOCK(rx_sleepLock); \
86 /* We now use beta semaphores for mutexes */
87 typedef b_sema_t afs_kmutex_t;
88 typedef caddr_t afs_kcondvar_t;
90 #else /* AFS_HPUX110_ENV */
92 #if defined(AFS_HPUX102_ENV)
93 #define CV_INIT(a,b,c,d)
95 #endif /* AFS_HPUX102_ENV */
96 #endif /* else AFS_HPUX110_ENV */
98 #ifdef AFS_HPUX102_ENV
100 #define RXObtainWriteLock(a) AFS_ASSERT_RXGLOCK()
101 #define RXReleaseWriteLock(a)
104 #if defined(AFS_HPUX110_ENV)
105 #undef osirx_AssertMine
106 extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
108 #define AFS_RX_ORDER 30
110 #define MUTEX_INIT(a,b,c,d) b_initsema((a), 1, AFS_RX_ORDER, (b))
111 #define MUTEX_DESTROY(a)
113 #define MUTEX_TRYENTER(a) b_cpsema(a)
115 #ifdef AFS_HPUX1111_ENV
116 #define MUTEX_ENTER(a) \
117 ((b_owns_sema(a)) ? osi_Panic("Already Held") : b_psema(a))
118 #define MUTEX_EXIT(a) \
119 ((b_owns_sema(a)) ? b_vsema(a) : osi_Panic("mutex not held"))
121 #define MUTEX_ENTER(a) \
122 ((b_owns_sema(a)) ? (osi_Panic("Already Held"), 0) : b_psema(a))
124 #define MUTEX_EXIT(a) \
125 ((b_owns_sema(a)) ? b_vsema(a) : (osi_Panic("mutex not held"), 0))
129 #define MUTEX_ISMINE(a) b_owns_sema(a)
131 #else /* AFS_HPUX110_ENV */
133 #define osirx_AssertMine(addr, msg)
135 #define MUTEX_DESTROY(a)
136 #define MUTEX_ENTER(a)
137 #define MUTEX_TRYENTER(a) 1
138 #define MUTEX_EXIT(a)
139 #define MUTEX_INIT(a,b,c,d)
141 #endif /* else AFS_HPUX110_ENV */
142 #endif /* AFS_HPUX102_ENV */
143 #endif /* _RX_KMUTEX_H_ */