Merge 1.8.0~pre4 packaging into master
[pkg-k5-afs_openafs.git] / src / rx / IRIX / rx_kmutex.h
blob5767a553027f02b5cd43720619aece20b8c7c4f4
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
11 * rx_kmutex.h - mutex and condition variable macros for kernel environment.
13 * IRIX implementation.
16 #ifndef _RX_KMUTEX_H_
17 #define _RX_KMUTEX_H_
19 #ifdef AFS_SGI62_ENV
21 #ifdef MP
22 #define RX_ENABLE_LOCKS 1
25 #include "sys/sema.h"
26 #ifndef mutex_tryenter
27 #define mutex_tryenter(m) cpsema(m)
28 #endif /* mutex_tryenter */
29 typedef kmutex_t afs_kmutex_t;
30 typedef kcondvar_t afs_kcondvar_t;
32 #ifndef CV_DEFAULT
33 #define CV_DEFAULT 0
34 #endif
35 #ifndef MUTEX_DEFAULT
36 #define MUTEX_DEFAULT 0
37 #endif
39 #ifdef AFS_SGI62_ENV
40 #define MUTEX_INIT(m, nm, type , a) mutex_init(m, type, nm)
41 #else
42 #define MUTEX_INIT(a,b,c,d) mutex_init(a,b,c,d)
43 #endif
44 #define MUTEX_DESTROY(a) mutex_destroy(a)
45 #define MUTEX_ASSERT(a)
46 #define CV_INIT(cv, a,b,c) cv_init(cv, a, b, c)
47 #define CV_SIGNAL(_cv) cv_signal(_cv)
48 #define CV_BROADCAST(_cv) cv_broadcast(_cv)
49 #define CV_DESTROY(_cv) cv_destroy(_cv)
50 #ifdef AFS_SGI64_ENV
51 /* Add PLTWAIT for afsd's to wait so we don't rack up the load average. */
52 #ifdef AFS_SGI65_ENV
53 #define AFSD_PRI() ((kt_basepri(curthreadp) == PTIME_SHARE) ? PZERO : (PZERO|PLTWAIT))
54 #else
55 #define AFSD_PRI() ((curprocp && curprocp->p_rss==0) ? (PZERO|PLTWAIT) : PZERO)
56 #endif /* SGI65 */
57 #undef cv_wait
58 #define cv_wait(cv, mp) { \
59 sv_wait(cv, AFSD_PRI(), mp, 0); \
60 AFS_MUTEX_ENTER(mp); \
62 #endif /* AFS_SGI64_ENV */
63 #ifdef RX_LOCKS_DB
64 #define MUTEX_ENTER(a) do { \
65 AFS_MUTEX_ENTER(a); \
66 rxdb_grablock((a), osi_ThreadUnique(), \
67 rxdb_fileID, __LINE__); \
68 } while(0)
69 #define MUTEX_TRYENTER(a) (mutex_tryenter(a) ? \
70 (rxdb_grablock((a), osi_ThreadUnique(), \
71 rxdb_fileID, __LINE__), 1) \
72 : 0)
73 #define MUTEX_EXIT(a) do { \
74 rxdb_droplock((a), osi_ThreadUnique(), \
75 rxdb_fileID, __LINE__); \
76 mutex_exit(a); \
77 } while(0)
78 #define CV_WAIT(_cv, _lck) do { \
79 int haveGlock = ISAFS_GLOCK(); \
80 if (haveGlock) \
81 AFS_GUNLOCK(); \
82 rxdb_droplock((_lck), \
83 osi_ThreadUnique(), \
84 rxdb_fileID, __LINE__); \
85 cv_wait(_cv, _lck); \
86 rxdb_grablock((_lck), \
87 osi_ThreadUnique(), \
88 rxdb_fileID, __LINE__); \
89 if (haveGlock) { \
90 MUTEX_EXIT(_lck); \
91 AFS_GLOCK(); \
92 MUTEX_ENTER(_lck); \
93 } \
94 } while (0)
95 #define CV_TIMEDWAIT(_cv,_lck,_t) do { \
96 int haveGlock = ISAFS_GLOCK(); \
97 if (haveGlock) \
98 AFS_GUNLOCK(); \
99 rxdb_droplock((_lck), \
100 osi_ThreadUnique(), \
101 rxdb_fileID, __LINE__); \
102 cv_timedwait(_cv, _lck, t); \
103 rxdb_grablock((_lck), \
104 osi_ThreadUnique(), \
105 rxdb_fileID, __LINE__); \
106 if (haveGlock) { \
107 MUTEX_EXIT(_lck); \
108 AFS_GLOCK(); \
109 MUTEX_ENTER(_lck); \
111 } while (0)
112 #else /* RX_LOCKS_DB */
113 #define MUTEX_ENTER(a) AFS_MUTEX_ENTER(a)
114 #define MUTEX_TRYENTER(a) mutex_tryenter(a)
115 #define MUTEX_EXIT(a) mutex_exit(a)
116 #define CV_WAIT(_cv, _lck) do { \
117 int haveGlock = ISAFS_GLOCK(); \
118 if (haveGlock) \
119 AFS_GUNLOCK(); \
120 cv_wait(_cv, _lck); \
121 if (haveGlock) { \
122 MUTEX_EXIT(_lck); \
123 AFS_GLOCK(); \
124 MUTEX_ENTER(_lck); \
126 } while (0)
127 #define CV_TIMEDWAIT(cv,lck,t) do { \
128 int haveGlock = ISAFS_GLOCK(); \
129 if (haveGlock) \
130 AFS_GUNLOCK(); \
131 cv_timedwait(_cv, _lck, t); \
132 if (haveGlock) { \
133 MUTEX_EXIT(_lck); \
134 AFS_GLOCK(); \
135 MUTEX_ENTER(_lck); \
137 } while (0)
138 #endif /* RX_LOCKS_DB */
141 #else /* MP */
142 #define MUTEX_INIT(m, nm, type , a)
143 #define MUTEX_DESTROY(a)
144 #define MUTEX_ASSERT(a)
145 #define MUTEX_ENTER(a)
146 #define MUTEX_TRYENTER(a) 1
147 #define MUTEX_EXIT(a)
149 #define CV_INIT(cv, a,b,c)
150 #define CV_SIGNAL(_cv)
151 #define CV_BROADCAST(_cv)
152 #define CV_DESTROY(_cv)
153 #define CV_WAIT(_cv, _lck)
154 #define CV_TIMEDWAIT(cv,lck,t)
156 #endif /* MP */
158 #endif /* SGI62 */
160 #endif /* _RX_KMUTEX_H_ */