Standardize License information
[openafs.git] / src / rx / DUX / rx_kmutex.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 /*
11  * rx_kmutex.h - mutex and condition variable macros for kernel environment.
12  *
13  * DUX implementation.
14  */
15
16 #ifndef _RX_KMUTEX_H_
17 #define _RX_KMUTEX_H_
18
19 #ifdef AFS_DUX40_ENV
20
21 #include <kern/lock.h>
22 #include <kern/sched_prim.h>
23 #include <sys/unix_defs.h>
24
25 #define RX_ENABLE_LOCKS         1
26 #define AFS_GLOBAL_RXLOCK_KERNEL
27
28 /*
29  * Condition variables
30  *
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.
34  */
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);      \
41                                 MUTEX_EXIT(lck);        \
42                                 thread_block();         \
43                                 if (isGlockOwner) AFS_GLOCK();  \
44                                 MUTEX_ENTER(lck); \
45                             }
46
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);  \
52                                 MUTEX_EXIT(lck);        \
53                                 thread_block();         \
54                                 if (isGlockOwner) AFS_GLOCK();  \
55                                 MUTEX_ENTER(lck);       \
56
57 #define CV_SIGNAL(cv)           thread_wakeup_one((vm_offset_t)(cv))
58 #define CV_BROADCAST(cv)        thread_wakeup((vm_offset_t)(cv))
59
60 typedef struct {
61     simple_lock_data_t lock;
62     thread_t owner;
63 } afs_kmutex_t;
64 typedef int afs_kcondvar_t;
65
66 #define osi_rxWakeup(cv)        thread_wakeup((vm_offset_t)(cv))
67
68 #define LOCK_INIT(a,b) \
69     do { \
70         usimple_lock_init(&(a)->lock); \
71         (a)->owner = (thread_t)0; \
72     } while(0);
73 #define MUTEX_INIT(a,b,c,d) \
74     do { \
75         usimple_lock_init(&(a)->lock); \
76         (a)->owner = (thread_t)0; \
77     } while(0);
78 #define MUTEX_DESTROY(a) \
79     do { \
80         usimple_lock_terminate(&(a)->lock); \
81         (a)->owner = (thread_t)-1; \
82     } while(0);
83 #define MUTEX_ENTER(a) \
84     do { \
85         usimple_lock(&(a)->lock); \
86         osi_Assert((a)->owner == (thread_t)0); \
87         (a)->owner = current_thread(); \
88     } while(0);
89 #define MUTEX_TRYENTER(a) \
90     ( usimple_lock_try(&(a)->lock) ? ((a)->owner = current_thread(), 1) : 0 )
91 #define MUTEX_EXIT(a) \
92     do { \
93         osi_Assert((a)->owner == current_thread()); \
94         (a)->owner = (thread_t)0; \
95         usimple_unlock(&(a)->lock); \
96     } while(0);
97
98 #undef MUTEX_ISMINE
99 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == current_thread())
100
101 #undef osirx_AssertMine
102 extern void osirx_AssertMine(afs_kmutex_t *lockaddr, char *msg);
103
104 #endif  /* DUX40 */
105
106
107 #endif /* _RX_KMUTEX_H_ */
108