1 /* Copyright Transarc Corporation 1998 - All Rights Reserved
3 * rx_kmutex.h - mutex and condition variable macros for kernel environment.
13 #include <kern/lock.h>
14 #include <kern/sched_prim.h>
15 #include <sys/unix_defs.h>
17 #define RX_ENABLE_LOCKS 1
18 #define AFS_GLOBAL_RXLOCK_KERNEL
23 * In Digital Unix (OSF/1), we use something akin to the ancient sleep/wakeup
24 * mechanism. The condition variable itself plays no role; we just use its
25 * address as a convenient unique number.
27 #define CV_INIT(cv,a,b,c)
28 #define CV_DESTROY(cv)
29 #define CV_WAIT(cv, lck) { \
30 int isGlockOwner = ISAFS_GLOCK(); \
31 if (isGlockOwner) AFS_GUNLOCK(); \
32 assert_wait((vm_offset_t)(cv), 0); \
35 if (isGlockOwner) AFS_GLOCK(); \
39 #define CV_TIMEDWAIT(cv,lck,t) { \
40 int isGlockOwner = ISAFS_GLOCK(); \
41 if (isGlockOwner) AFS_GUNLOCK(); \
42 assert_wait((vm_offset_t)(cv), 0); \
43 thread_set_timeout(t); \
46 if (isGlockOwner) AFS_GLOCK(); \
49 #define CV_SIGNAL(cv) thread_wakeup_one((vm_offset_t)(cv))
50 #define CV_BROADCAST(cv) thread_wakeup((vm_offset_t)(cv))
53 simple_lock_data_t lock;
56 typedef int afs_kcondvar_t;
58 #define osi_rxWakeup(cv) thread_wakeup((vm_offset_t)(cv))
60 #define LOCK_INIT(a,b) \
62 usimple_lock_init(&(a)->lock); \
63 (a)->owner = (thread_t)0; \
65 #define MUTEX_INIT(a,b,c,d) \
67 usimple_lock_init(&(a)->lock); \
68 (a)->owner = (thread_t)0; \
70 #define MUTEX_DESTROY(a) \
72 usimple_lock_terminate(&(a)->lock); \
73 (a)->owner = (thread_t)-1; \
75 #define MUTEX_ENTER(a) \
77 usimple_lock(&(a)->lock); \
78 osi_Assert((a)->owner == (thread_t)0); \
79 (a)->owner = current_thread(); \
81 #define MUTEX_TRYENTER(a) \
82 ( usimple_lock_try(&(a)->lock) ? ((a)->owner = current_thread(), 1) : 0 )
83 #define MUTEX_EXIT(a) \
85 osi_Assert((a)->owner == current_thread()); \
86 (a)->owner = (thread_t)0; \
87 usimple_unlock(&(a)->lock); \
91 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == current_thread())
93 #undef osirx_AssertMine
94 extern void osirx_AssertMine(afs_kmutex_t *lockaddr, char *msg);
99 #endif /* _RX_KMUTEX_H_ */