OpenAFS
OpenAFS distributed network file system
|
00001 /* 00002 * Copyright 2000, International Business Machines Corporation and others. 00003 * All Rights Reserved. 00004 * 00005 * This software has been released under the terms of the IBM Public 00006 * License. For details, see the LICENSE file in the top-level source 00007 * directory or online at http://www.openafs.org/dl/license10.html 00008 */ 00009 00010 /* 00011 * rx_kmutex.h - mutex and condition variable macros for kernel environment. 00012 * 00013 * IRIX implementation. 00014 */ 00015 00016 #ifndef _RX_KMUTEX_H_ 00017 #define _RX_KMUTEX_H_ 00018 00019 #ifdef AFS_SGI62_ENV 00020 00021 #ifdef MP 00022 #define RX_ENABLE_LOCKS 1 00023 #define AFS_GLOBAL_RXLOCK_KERNEL 1 00024 00025 00026 #include "sys/sema.h" 00027 #ifndef mutex_tryenter 00028 #define mutex_tryenter(m) cpsema(m) 00029 #endif /* mutex_tryenter */ 00030 typedef kmutex_t afs_kmutex_t; 00031 typedef kcondvar_t afs_kcondvar_t; 00032 00033 #ifndef CV_DEFAULT 00034 #define CV_DEFAULT 0 00035 #endif 00036 #ifndef MUTEX_DEFAULT 00037 #define MUTEX_DEFAULT 0 00038 #endif 00039 00040 #ifdef AFS_SGI62_ENV 00041 #define MUTEX_INIT(m, nm, type , a) mutex_init(m, type, nm) 00042 #else 00043 #define MUTEX_INIT(a,b,c,d) mutex_init(a,b,c,d) 00044 #endif 00045 #define MUTEX_DESTROY(a) mutex_destroy(a) 00046 #undef MUTEX_ISMINE 00047 #define MUTEX_ISMINE(a) 1 00048 #define CV_INIT(cv, a,b,c) cv_init(cv, a, b, c) 00049 #define CV_SIGNAL(_cv) cv_signal(_cv) 00050 #define CV_BROADCAST(_cv) cv_broadcast(_cv) 00051 #define CV_DESTROY(_cv) cv_destroy(_cv) 00052 #undef osirx_AssertMine 00053 extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg); 00054 #ifdef AFS_SGI64_ENV 00055 /* Add PLTWAIT for afsd's to wait so we don't rack up the load average. */ 00056 #ifdef AFS_SGI65_ENV 00057 #define AFSD_PRI() ((kt_basepri(curthreadp) == PTIME_SHARE) ? PZERO : (PZERO|PLTWAIT)) 00058 #else 00059 #define AFSD_PRI() ((curprocp && curprocp->p_rss==0) ? (PZERO|PLTWAIT) : PZERO) 00060 #endif /* SGI65 */ 00061 #undef cv_wait 00062 #define cv_wait(cv, mp) { \ 00063 sv_wait(cv, AFSD_PRI(), mp, 0); \ 00064 AFS_MUTEX_ENTER(mp); \ 00065 } 00066 #endif /* AFS_SGI64_ENV */ 00067 #ifdef RX_LOCKS_DB 00068 #define MUTEX_ENTER(a) do { \ 00069 AFS_MUTEX_ENTER(a); \ 00070 rxdb_grablock((a), osi_ThreadUnique(), \ 00071 rxdb_fileID, __LINE__); \ 00072 } while(0) 00073 #define MUTEX_TRYENTER(a) (mutex_tryenter(a) ? \ 00074 (rxdb_grablock((a), osi_ThreadUnique(), \ 00075 rxdb_fileID, __LINE__), 1) \ 00076 : 0) 00077 #define MUTEX_EXIT(a) do { \ 00078 rxdb_droplock((a), osi_ThreadUnique(), \ 00079 rxdb_fileID, __LINE__); \ 00080 mutex_exit(a); \ 00081 } while(0) 00082 #define CV_WAIT(_cv, _lck) do { \ 00083 int haveGlock = ISAFS_GLOCK(); \ 00084 if (haveGlock) \ 00085 AFS_GUNLOCK(); \ 00086 rxdb_droplock((_lck), \ 00087 osi_ThreadUnique(), \ 00088 rxdb_fileID, __LINE__); \ 00089 cv_wait(_cv, _lck); \ 00090 rxdb_grablock((_lck), \ 00091 osi_ThreadUnique(), \ 00092 rxdb_fileID, __LINE__); \ 00093 if (haveGlock) { \ 00094 MUTEX_EXIT(_lck); \ 00095 AFS_GLOCK(); \ 00096 MUTEX_ENTER(_lck); \ 00097 } \ 00098 } while (0) 00099 #define CV_TIMEDWAIT(_cv,_lck,_t) do { \ 00100 int haveGlock = ISAFS_GLOCK(); \ 00101 if (haveGlock) \ 00102 AFS_GUNLOCK(); \ 00103 rxdb_droplock((_lck), \ 00104 osi_ThreadUnique(), \ 00105 rxdb_fileID, __LINE__); \ 00106 cv_timedwait(_cv, _lck, t); \ 00107 rxdb_grablock((_lck), \ 00108 osi_ThreadUnique(), \ 00109 rxdb_fileID, __LINE__); \ 00110 if (haveGlock) { \ 00111 MUTEX_EXIT(_lck); \ 00112 AFS_GLOCK(); \ 00113 MUTEX_ENTER(_lck); \ 00114 } \ 00115 } while (0) 00116 #else /* RX_LOCKS_DB */ 00117 #define MUTEX_ENTER(a) AFS_MUTEX_ENTER(a) 00118 #define MUTEX_TRYENTER(a) mutex_tryenter(a) 00119 #define MUTEX_EXIT(a) mutex_exit(a) 00120 #define CV_WAIT(_cv, _lck) do { \ 00121 int haveGlock = ISAFS_GLOCK(); \ 00122 if (haveGlock) \ 00123 AFS_GUNLOCK(); \ 00124 cv_wait(_cv, _lck); \ 00125 if (haveGlock) { \ 00126 MUTEX_EXIT(_lck); \ 00127 AFS_GLOCK(); \ 00128 MUTEX_ENTER(_lck); \ 00129 } \ 00130 } while (0) 00131 #define CV_TIMEDWAIT(cv,lck,t) do { \ 00132 int haveGlock = ISAFS_GLOCK(); \ 00133 if (haveGlock) \ 00134 AFS_GUNLOCK(); \ 00135 cv_timedwait(_cv, _lck, t); \ 00136 if (haveGlock) { \ 00137 MUTEX_EXIT(_lck); \ 00138 AFS_GLOCK(); \ 00139 MUTEX_ENTER(_lck); \ 00140 } \ 00141 } while (0) 00142 #endif /* RX_LOCKS_DB */ 00143 00144 00145 #else /* MP */ 00146 #define MUTEX_INIT(m, nm, type , a) 00147 #define MUTEX_DESTROY(a) 00148 #define MUTEX_ISMINE(a) 1 00149 #define MUTEX_ENTER(a) 00150 #define MUTEX_TRYENTER(a) 1 00151 #define MUTEX_EXIT(a) 00152 00153 #define osirx_AssertMine(addr, msg) 00154 00155 #define CV_INIT(cv, a,b,c) 00156 #define CV_SIGNAL(_cv) 00157 #define CV_BROADCAST(_cv) 00158 #define CV_DESTROY(_cv) 00159 #define CV_WAIT(_cv, _lck) 00160 #define CV_TIMEDWAIT(cv,lck,t) 00161 00162 #endif /* MP */ 00163 00164 #endif /* SGI62 */ 00165 00166 #endif /* _RX_KMUTEX_H_ */