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.
13 * MACOS implementation.
20 #include <kern/thread.h>
23 #define RX_ENABLE_LOCKS 1
24 #define AFS_GLOBAL_RXLOCK_KERNEL
29 * In Digital Unix (OSF/1), we use something akin to the ancient sleep/wakeup
30 * mechanism. The condition variable itself plays no role; we just use its
31 * address as a convenient unique number.
33 * XXX in darwin, both mach and bsd facilities are available. Should really
34 * stick to one or the other (but mach locks don't have a _try.....)
36 #define CV_INIT(cv,a,b,c)
37 #define CV_DESTROY(cv)
38 #ifdef AFS_DARWIN14_ENV
39 #define CV_WAIT(cv, lck) { \
40 int isGlockOwner = ISAFS_GLOCK(); \
41 if (isGlockOwner) AFS_GUNLOCK(); \
44 if (isGlockOwner) AFS_GLOCK(); \
48 #define CV_TIMEDWAIT(cv,lck,t) { \
49 int isGlockOwner = ISAFS_GLOCK(); \
50 if (isGlockOwner) AFS_GUNLOCK(); \
52 tsleep(cv,PVFS, "afs_CV_TIMEDWAIT",t); \
53 if (isGlockOwner) AFS_GLOCK(); \
57 #define CV_SIGNAL(cv) wakeup_one(cv)
58 #define CV_BROADCAST(cv) wakeup(cv)
60 #define CV_WAIT(cv, lck) { \
61 int isGlockOwner = ISAFS_GLOCK(); \
62 if (isGlockOwner) AFS_GUNLOCK(); \
63 assert_wait((event_t)(cv), 0); \
66 if (isGlockOwner) AFS_GLOCK(); \
70 #define CV_TIMEDWAIT(cv,lck,t) { \
71 int isGlockOwner = ISAFS_GLOCK(); \
72 if (isGlockOwner) AFS_GUNLOCK(); \
73 assert_wait((event_t)(cv), 0); \
74 thread_set_timer(t, NSEC_PER_SEC/hz); \
77 if (isGlockOwner) AFS_GLOCK(); \
81 #define CV_SIGNAL(cv) thread_wakeup_one((event_t)(cv))
82 #define CV_BROADCAST(cv) thread_wakeup((event_t)(cv))
86 struct lock__bsd__ lock;
89 typedef int afs_kcondvar_t;
91 #define osi_rxWakeup(cv) thread_wakeup((event_t)(cv))
93 #define LOCK_INIT(a,b) \
95 lockinit(&(a)->lock,PSOCK, "afs rx lock", 0, 0); \
96 (a)->owner = (thread_t)0; \
98 #define MUTEX_INIT(a,b,c,d) \
100 lockinit(&(a)->lock,PSOCK, "afs rx mutex", 0, 0); \
101 (a)->owner = (thread_t)0; \
103 #define MUTEX_DESTROY(a) \
105 (a)->owner = (thread_t)-1; \
107 #define MUTEX_ENTER(a) \
109 lockmgr(&(a)->lock, LK_EXCLUSIVE, 0, current_proc()); \
110 osi_Assert((a)->owner == (thread_t)0); \
111 (a)->owner = current_thread(); \
113 #define MUTEX_TRYENTER(a) \
114 ( lockmgr(&(a)->lock, LK_EXCLUSIVE|LK_NOWAIT, 0, current_proc()) ? 0 : ((a)->owner = current_thread(), 1) )
115 #define xMUTEX_TRYENTER(a) \
116 ( osi_Assert((a)->owner == (thread_t)0), (a)->owner = current_thread(), 1)
117 #define MUTEX_EXIT(a) \
119 osi_Assert((a)->owner == current_thread()); \
120 (a)->owner = (thread_t)0; \
121 lockmgr(&(a)->lock, LK_RELEASE, 0, current_proc()); \
125 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == current_thread())
127 #undef osirx_AssertMine
128 extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
130 #endif /* _RX_KMUTEX_H_ */