rx: Get rid of AFS_GLOBAL_RXLOCK_KERNEL
[openafs.git] / src / rx / AIX / 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  * AIX 4.x implementation.
14  */
15
16 #ifndef _RX_KMUTEX_H_
17 #define _RX_KMUTEX_H_
18
19 #ifdef AFS_AIX41_ENV
20
21
22 #undef  LOCK_INIT
23 #include <sys/lockl.h>
24 #include <sys/lock_def.h>
25 #include <sys/lock_alloc.h>
26 #include <sys/sleep.h>
27 #define RX_ENABLE_LOCKS         1
28 /*
29  * `condition variables' -- well, not really.  these just map to the
30  * AIX event-list routines.  Thus, if one signals a condition prior to
31  * a process waiting for it, the signal gets lost.
32  * Note:
33  *      `t' in `cv_timedwait' has different interpretation
34  */
35 #ifndef CV_DEFAULT
36 #define CV_DEFAULT      0
37 #endif
38 #ifndef MUTEX_DEFAULT
39 #define MUTEX_DEFAULT   0
40 #endif
41 #define CV_INIT(cv, a,b,c)      (*(cv) = EVENT_NULL)
42 #define CV_DESTROY(cv)
43 #define CV_SIGNAL(_cv)          e_wakeup_one(_cv)
44 #define CV_BROADCAST(_cv)       e_wakeup(_cv)
45 typedef simple_lock_data afs_kmutex_t;
46 typedef tid_t afs_kcondvar_t;
47
48
49 #define LOCK_INIT(a, b)         lock_alloc((void*)(a), LOCK_ALLOC_PIN, 1, 1), \
50                                 simple_lock_init((void *)(a))
51 #define MUTEX_INIT(a,b,c,d)     lock_alloc((void*)(a), LOCK_ALLOC_PIN, 1, 1), \
52                                 simple_lock_init((void *)(a))
53 #define MUTEX_DESTROY(a)        lock_free((void*)(a))
54
55 #ifdef RX_LOCKS_DB
56
57 #define MUTEX_ENTER(a)          simple_lock((void *)(a)), \
58                                 rxdb_grablock((void *)(a), thread_self(),rxdb_fileID,\
59                                               __LINE__)
60
61 #define MUTEX_TRYENTER(a)       (simple_lock_try((void *)(a)) ?\
62                                 rxdb_grablock((void *)(a), thread_self(), rxdb_fileID,\
63                                               __LINE__), 1 : 0)
64
65 #define MUTEX_EXIT(a)           rxdb_droplock((void *)(a), thread_self(), rxdb_fileID,\
66                                               __LINE__), \
67                                 simple_unlock((void *)(a))
68
69 #define CV_WAIT(_cv, _lck) \
70     do { \
71         int haveGlock = ISAFS_GLOCK(); \
72         if (haveGlock) \
73             AFS_GUNLOCK(); \
74         rxdb_droplock((void *)(_lck), thread_self(), rxdb_fileID, __LINE__); \
75         e_sleep_thread((_cv), (_lck), LOCK_SIMPLE); \
76         rxdb_grablock((void *)(_lck), thread_self(), rxdb_fileID, __LINE__); \
77         if (haveGlock) { \
78             MUTEX_EXIT(_lck); \
79             AFS_GLOCK(); \
80             MUTEX_ENTER(_lck); \
81         } \
82     } while(0)
83
84 #define CV_TIMEDWAIT(_cv, _lck, _t) \
85     do { \
86         int haveGlock = ISAFS_GLOCK(); \
87         if (haveGlock) \
88             AFS_GUNLOCK(); \
89         rxdb_droplock((void *)(_lck), thread_self(), rxdb_fileID, __LINE__); \
90         e_mpsleep((_cv), (_t), (_lck), LOCK_SIMPLE); \
91         rxdb_grablock((void *)(_lck), thread_self(), rxdb_fileID, __LINE__); \
92         if (haveGlock) { \
93             MUTEX_EXIT(_lck); \
94             AFS_GLOCK(); \
95             MUTEX_ENTER(_lck); \
96         } \
97     } while(0)
98
99 #else /* RX_LOCK_DB */
100
101 #define MUTEX_ENTER(a)          simple_lock((void *)(a))
102 #define MUTEX_TRYENTER(a)       simple_lock_try((void *)(a))
103 #define MUTEX_EXIT(a)           simple_unlock((void *)(a))
104
105 #define CV_WAIT(_cv, _lck) \
106     do { \
107         int haveGlock = ISAFS_GLOCK(); \
108         if (haveGlock) \
109             AFS_GUNLOCK(); \
110         e_sleep_thread((_cv), (_lck), LOCK_SIMPLE); \
111         if (haveGlock) { \
112             MUTEX_EXIT(_lck); \
113             AFS_GLOCK(); \
114             MUTEX_ENTER(_lck); \
115         } \
116     } while(0)
117
118 #define CV_TIMEDWAIT(_cv, _lck, _t) \
119     do { \
120         int haveGlock = ISAFS_GLOCK(); \
121         if (haveGlock) \
122             AFS_GUNLOCK(); \
123         e_mpsleep((_cv), (_t), (_lck), LOCK_SIMPLE); \
124         if (haveGlock) { \
125             MUTEX_EXIT(_lck); \
126             AFS_GLOCK(); \
127             MUTEX_ENTER(_lck); \
128         } \
129     } while(0)
130
131 #endif /* RX_LOCK_DB */
132
133 #define MUTEX_DEFAULT   0
134
135 #undef MUTEX_ISMINE
136 #define MUTEX_ISMINE(a) (lock_mine((void *)(a)))
137
138 #undef osirx_AssertMine
139 extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
140
141 #endif /* AFS_AIX41_ENV */
142
143 #endif /* _RX_KMUTEX_H_ */