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