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 /* rx_kmutex.h - mutex and condition variable macros for kernel environment. 00011 * 00012 * HPUX implementation. 00013 */ 00014 00015 #ifndef _RX_KMUTEX_H_ 00016 #define _RX_KMUTEX_H_ 00017 00018 #if defined(AFS_HPUX110_ENV) && defined(KERNEL) 00019 /* rx fine grain locking primitives */ 00020 00021 #include <sys/ksleep.h> 00022 #include <sys/spinlock.h> 00023 #include <sys/sem_beta.h> 00024 #include <sys/errno.h> 00025 #include <net/netmp.h> 00026 00027 #include "../rx/rx_kernel.h" /* For osi_Panic() */ 00028 00029 #define RX_ENABLE_LOCKS 1 00030 #define AFS_GLOBAL_RXLOCK_KERNEL 00031 00032 extern lock_t *rx_sleepLock; 00033 00034 /* We use beta semaphores instead of sync semaphores for Rx locks as 00035 * recommended by HP labs. Sync semaphores are not supported by HP 00036 * any more. 00037 */ 00038 00039 #define CV_INIT(cv,a,b,c) 00040 00041 /* This is supposed to atomically drop the mutex and go to sleep 00042 * and reacquire the mutex when it wakes up. 00043 */ 00044 00045 /* With 11.23, ksleep_prepare is not defined anywhere and 00046 * ksleep_one is only referenced in a comment. sleep, get_sleep_lock 00047 * and wakeup are defined in driver manuals. 00048 * This works with 11.0, 11i, and 11.23 00049 * Note: wakeup wakes up all threads waiting on cv. 00050 */ 00051 00052 #define CV_WAIT(cv, lck) \ 00053 do { \ 00054 get_sleep_lock((caddr_t)(cv)); \ 00055 if (!b_owns_sema(lck)) \ 00056 osi_Panic("CV_WAIT mutex not held \n"); \ 00057 b_vsema(lck); \ 00058 sleep((caddr_t)(cv), PRIBIO); \ 00059 b_psema(lck); \ 00060 } while(0) 00061 00062 #define CV_SIGNAL(cv) \ 00063 do { \ 00064 lock_t * sleep_lock = get_sleep_lock((caddr_t)(cv)); \ 00065 wakeup((caddr_t)(cv)); \ 00066 spinunlock(sleep_lock); \ 00067 } while(0) 00068 00069 #define CV_BROADCAST(cv) \ 00070 do { \ 00071 lock_t * sleep_lock = get_sleep_lock((caddr_t)(cv)); \ 00072 wakeup((caddr_t)(cv)); \ 00073 spinunlock(sleep_lock); \ 00074 } while(0) 00075 00076 00077 #if 0 00078 #define CV_WAIT(cv, lck) \ 00079 do { \ 00080 int code; \ 00081 ksleep_prepare(); \ 00082 MP_SPINLOCK(rx_sleepLock); \ 00083 if (!b_owns_sema(lck)) \ 00084 osi_Panic("mutex not held \n"); \ 00085 b_vsema(lck); \ 00086 code = ksleep_one(PCATCH | KERNEL_ADDRESS | KERN_SPINLOCK_OBJECT, \ 00087 (cv), rx_sleepLock, 0); \ 00088 if (code) { \ 00089 if (code == EINTR) { /* lock still held */ \ 00090 MP_SPINUNLOCK(rx_sleepLock); \ 00091 } else if (code != -EINTR) { \ 00092 osi_Panic("ksleep_one failed: code = %d \n", code); \ 00093 } \ 00094 } \ 00095 b_psema(lck); /* grab the mutex again */ \ 00096 } while(0) 00097 00098 /* Wakes up a thread waiting on this condition */ 00099 #define CV_SIGNAL(cv) \ 00100 do { \ 00101 int wo, code; \ 00102 MP_SPINLOCK(rx_sleepLock); \ 00103 if ((code = kwakeup_one(KERNEL_ADDRESS, (cv), WAKEUP_ONE, &wo)) < 0) \ 00104 osi_Panic("kwakeup_one failed: code = %d \n", code); \ 00105 MP_SPINUNLOCK(rx_sleepLock); \ 00106 } while (0) 00107 00108 /* Wakes up all threads waiting on this condition */ 00109 #define CV_BROADCAST(cv) \ 00110 do { \ 00111 int wo, code; \ 00112 MP_SPINLOCK(rx_sleepLock); \ 00113 if ((code = kwakeup_one(KERNEL_ADDRESS, (cv), WAKEUP_ALL, &wo)) < 0) \ 00114 osi_Panic("kwakeup_all failed: code = %d \n", code); \ 00115 MP_SPINUNLOCK(rx_sleepLock); \ 00116 } while (0) 00117 #endif /* 0 */ 00118 00119 #define CV_DESTROY(a) 00120 00121 /* We now use beta semaphores for mutexes */ 00122 typedef b_sema_t afs_kmutex_t; 00123 typedef caddr_t afs_kcondvar_t; 00124 00125 #else /* AFS_HPUX110_ENV */ 00126 00127 #if defined(AFS_HPUX102_ENV) 00128 #define CV_INIT(a,b,c,d) 00129 #define CV_DESTROY(a) 00130 #endif /* AFS_HPUX102_ENV */ 00131 #endif /* else AFS_HPUX110_ENV */ 00132 00133 #ifdef AFS_HPUX102_ENV 00134 00135 #if defined(AFS_HPUX110_ENV) 00136 #undef osirx_AssertMine 00137 extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg); 00138 00139 #define AFS_RX_ORDER 30 00140 00141 #define MUTEX_INIT(a,b,c,d) b_initsema((a), 1, AFS_RX_ORDER, (b)) 00142 #define MUTEX_DESTROY(a) 00143 00144 #define MUTEX_TRYENTER(a) b_cpsema(a) 00145 00146 #ifdef AFS_HPUX1111_ENV 00147 #define MUTEX_ENTER(a) \ 00148 ((b_owns_sema(a)) ? osi_Panic("Already Held") : b_psema(a)) 00149 #define MUTEX_EXIT(a) \ 00150 ((b_owns_sema(a)) ? b_vsema(a) : osi_Panic("mutex not held")) 00151 #else 00152 #define MUTEX_ENTER(a) \ 00153 ((b_owns_sema(a)) ? (osi_Panic("Already Held"), 0) : b_psema(a)) 00154 00155 #define MUTEX_EXIT(a) \ 00156 ((b_owns_sema(a)) ? b_vsema(a) : (osi_Panic("mutex not held"), 0)) 00157 #endif 00158 00159 #undef MUTEX_ISMINE 00160 #define MUTEX_ISMINE(a) b_owns_sema(a) 00161 00162 #else /* AFS_HPUX110_ENV */ 00163 00164 #define osirx_AssertMine(addr, msg) 00165 00166 #define MUTEX_DESTROY(a) 00167 #define MUTEX_ENTER(a) 00168 #define MUTEX_TRYENTER(a) 1 00169 #define MUTEX_EXIT(a) 00170 #define MUTEX_INIT(a,b,c,d) 00171 00172 #endif /* else AFS_HPUX110_ENV */ 00173 #endif /* AFS_HPUX102_ENV */ 00174 #endif /* _RX_KMUTEX_H_ */