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.
21 #include <kern/lock.h>
22 #include <kern/sched_prim.h>
23 #include <sys/unix_defs.h>
25 #define RX_ENABLE_LOCKS 1
26 #define AFS_GLOBAL_RXLOCK_KERNEL
31 * In Digital Unix (OSF/1), we use something akin to the ancient sleep/wakeup
32 * mechanism. The condition variable itself plays no role; we just use its
33 * address as a convenient unique number.
35 #define CV_INIT(cv,a,b,c)
36 #define CV_DESTROY(cv)
37 #define CV_WAIT(cv, lck) { \
38 int isGlockOwner = ISAFS_GLOCK(); \
39 if (isGlockOwner) AFS_GUNLOCK(); \
40 assert_wait((vm_offset_t)(cv), 0); \
43 if (isGlockOwner) AFS_GLOCK(); \
47 #define CV_TIMEDWAIT(cv,lck,t) { \
48 int isGlockOwner = ISAFS_GLOCK(); \
49 if (isGlockOwner) AFS_GUNLOCK(); \
50 assert_wait((vm_offset_t)(cv), 0); \
51 thread_set_timeout(t); \
54 if (isGlockOwner) AFS_GLOCK(); \
58 #define CV_SIGNAL(cv) thread_wakeup_one((vm_offset_t)(cv))
59 #define CV_BROADCAST(cv) thread_wakeup((vm_offset_t)(cv))
62 simple_lock_data_t lock;
65 typedef int afs_kcondvar_t;
67 #define osi_rxWakeup(cv) thread_wakeup((vm_offset_t)(cv))
69 #define LOCK_INIT(a,b) \
71 usimple_lock_init(&(a)->lock); \
72 (a)->owner = (thread_t)0; \
74 #define MUTEX_INIT(a,b,c,d) \
76 usimple_lock_init(&(a)->lock); \
77 (a)->owner = (thread_t)0; \
79 #define MUTEX_DESTROY(a) \
81 usimple_lock_terminate(&(a)->lock); \
82 (a)->owner = (thread_t)-1; \
84 #define MUTEX_ENTER(a) \
86 usimple_lock(&(a)->lock); \
87 osi_Assert((a)->owner == (thread_t)0); \
88 (a)->owner = current_thread(); \
90 #define MUTEX_TRYENTER(a) \
91 ( usimple_lock_try(&(a)->lock) ? ((a)->owner = current_thread(), 1) : 0 )
92 #define MUTEX_EXIT(a) \
94 osi_Assert((a)->owner == current_thread()); \
95 (a)->owner = (thread_t)0; \
96 usimple_unlock(&(a)->lock); \
100 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == current_thread())
102 #undef osirx_AssertMine
103 extern void osirx_AssertMine(afs_kmutex_t *lockaddr, char *msg);
108 #endif /* _RX_KMUTEX_H_ */