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 * OpenBSD implementation by Jim Rees. 00014 */ 00015 00016 #ifndef _RX_KMUTEX_H_ 00017 #define _RX_KMUTEX_H_ 00018 00019 #include <sys/lock.h> 00020 00021 /* You can't have AFS_GLOBAL_SUNLOCK and not RX_ENABLE_LOCKS */ 00022 #define RX_ENABLE_LOCKS 1 00023 #define AFS_GLOBAL_RXLOCK_KERNEL 00024 00025 /* This is incomplete and probably wouldn't work with NCPUS > 1 */ 00026 00027 typedef int afs_kcondvar_t; 00028 00029 #define CV_INIT(cv, a, b, c) 00030 #define CV_DESTROY(cv) 00031 #define CV_WAIT(cv, lck) { \ 00032 int isGlockOwner = ISAFS_GLOCK(); \ 00033 if (isGlockOwner) AFS_GUNLOCK(); \ 00034 MUTEX_EXIT(lck); \ 00035 tsleep(cv, PSOCK, "afs_rx_cv_wait", 0); \ 00036 if (isGlockOwner) AFS_GLOCK(); \ 00037 MUTEX_ENTER(lck); \ 00038 } 00039 #define CV_SIGNAL(cv) wakeup_one(cv) 00040 #define CV_BROADCAST(cv) wakeup(cv) 00041 00042 typedef struct { 00043 struct proc *owner; 00044 } afs_kmutex_t; 00045 00046 #define MUTEX_DEFAULT 0 00047 00048 #define MUTEX_INIT(a,b,c,d) \ 00049 do { \ 00050 (a)->owner = 0; \ 00051 } while(0); 00052 #define MUTEX_DESTROY(a) \ 00053 do { \ 00054 (a)->owner = (struct proc *)-1; \ 00055 } while(0); 00056 #define MUTEX_ENTER(a) \ 00057 do { \ 00058 osi_Assert((a)->owner == 0); \ 00059 (a)->owner = curproc; \ 00060 } while(0); 00061 #define MUTEX_TRYENTER(a) \ 00062 ( osi_Assert((a)->owner == 0), (a)->owner = curproc, 1) 00063 #define MUTEX_EXIT(a) \ 00064 do { \ 00065 osi_Assert((a)->owner == curproc); \ 00066 (a)->owner = 0; \ 00067 } while(0); 00068 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == curproc) 00069 00070 #endif /* _RX_KMUTEX_H_ */