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_sync.h>
24 #include <sys/errno.h>
25 #include <net/netmp.h>
27 #define RX_ENABLE_LOCKS 1
28 #define AFS_GLOBAL_RXLOCK_KERNEL
29 extern lock_t* rx_sleepLock;
31 #define CV_INIT(cv,a,b,c)
33 /* this is supposed to atomically drop the mutex and go to sleep */
34 /* reacquire the mutex when the sleep is done */
35 #define CV_WAIT(cv, lck) { \
38 MP_SPINLOCK(rx_sleepLock); \
39 if (valusync(lck) < 1) \
42 osi_Panic("mutex not held %d",valusync(lck)); \
43 code=ksleep_one(KERNEL_ADDRESS|KERN_SPINLOCK_OBJECT,\
44 (cv),rx_sleepLock,0); \
46 if ( code == EINTR ) {/* lock still held */ \
47 MP_SPINUNLOCK(rx_sleepLock); \
48 } else if (code != -EINTR) { \
49 osi_Panic("ksleep_one failed %d", code);\
52 psync(lck); /* grab the mutex again */ \
55 /* Wakes up one thread waiting on this condition */
56 #define CV_SIGNAL(cv) { \
58 MP_SPINLOCK(rx_sleepLock); \
59 if( (code = kwakeup_one(KERNEL_ADDRESS,(cv), \
60 WAKEUP_ONE, &wo))<0) \
61 osi_Panic("kwakeup_one failed %d", code); \
62 MP_SPINUNLOCK(rx_sleepLock); \
65 /* wakeup all threads waiting on this condition */
66 #define CV_BROADCAST(cv) { \
68 MP_SPINLOCK(rx_sleepLock); \
69 if( (code = kwakeup_one(KERNEL_ADDRESS,(cv), \
70 WAKEUP_ALL, &wo))<0) \
71 osi_Panic("kwakeup_all failed %d", code); \
72 MP_SPINUNLOCK(rx_sleepLock); \
75 typedef sync_t afs_kmutex_t;
76 typedef caddr_t afs_kcondvar_t;
78 #else /* AFS_HPUX110_ENV */
80 #if defined(AFS_HPUX102_ENV)
81 #define CV_INIT(a,b,c,d)
83 #endif /* AFS_HPUX102_ENV */
84 #endif /* else AFS_HPUX110_ENV */
86 #ifdef AFS_HPUX102_ENV
88 #define RXObtainWriteLock(a) AFS_ASSERT_RXGLOCK()
89 #define RXReleaseWriteLock(a)
92 #if defined(AFS_HPUX110_ENV)
93 #undef osirx_AssertMine
94 extern void osirx_AssertMine(afs_kmutex_t *lockaddr, char *msg);
96 #define MUTEX_DESTROY(a) ( dealloc_spinlock((a)->s_lock) )
97 #define MUTEX_ENTER(a) psync(a)
98 #define MUTEX_TRYENTER(a) ( (valusync(a)==1)? (MUTEX_ENTER(a), 1):0 )
99 #define MUTEX_EXIT(a) ((valusync(a)<1)? vsync(a) : \
100 osi_Panic("mutex not held"))
101 #define MUTEX_INIT(a,b,c,d) (initsync(a), vsync(a))
104 #define MUTEX_ISMINE(a) ( (valusync(a)<1) ? 1 : 0 )
106 #else /* AFS_HPUX110_ENV */
108 #define osirx_AssertMine(addr, msg)
110 #define MUTEX_DESTROY(a)
111 #define MUTEX_ENTER(a)
112 #define MUTEX_TRYENTER(a) 1
113 #define MUTEX_EXIT(a)
114 #define MUTEX_INIT(a,b,c,d)
116 #endif /* else AFS_HPUX110_ENV */
117 #endif /* AFS_HPUX102_ENV */
118 #endif /* _RX_KMUTEX_H_ */