OpenAFS
OpenAFS distributed network file system
/cygdrive/c/src/openafs/openafs.git/repo/src/rx/AIX/rx_kmutex.h
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  * AIX 4.x implementation.
00014  */
00015 
00016 #ifndef _RX_KMUTEX_H_
00017 #define _RX_KMUTEX_H_
00018 
00019 #ifdef AFS_AIX41_ENV
00020 
00021 
00022 #undef  LOCK_INIT
00023 #include <sys/lockl.h>
00024 #include <sys/lock_def.h>
00025 #include <sys/lock_alloc.h>
00026 #include <sys/sleep.h>
00027 #define RX_ENABLE_LOCKS         1
00028 #define AFS_GLOBAL_RXLOCK_KERNEL
00029 /*
00030  * `condition variables' -- well, not really.  these just map to the
00031  * AIX event-list routines.  Thus, if one signals a condition prior to
00032  * a process waiting for it, the signal gets lost.
00033  * Note:
00034  *      `t' in `cv_timedwait' has different interpretation
00035  */
00036 #ifndef CV_DEFAULT
00037 #define CV_DEFAULT      0
00038 #endif
00039 #ifndef MUTEX_DEFAULT
00040 #define MUTEX_DEFAULT   0
00041 #endif
00042 #define CV_INIT(cv, a,b,c)      (*(cv) = EVENT_NULL)
00043 #define CV_DESTROY(cv)
00044 #define CV_SIGNAL(_cv)          e_wakeup_one(_cv)
00045 #define CV_BROADCAST(_cv)       e_wakeup(_cv)
00046 typedef simple_lock_data afs_kmutex_t;
00047 typedef tid_t afs_kcondvar_t;
00048 
00049 
00050 #define LOCK_INIT(a, b)         lock_alloc((void*)(a), LOCK_ALLOC_PIN, 1, 1), \
00051                                 simple_lock_init((void *)(a))
00052 #define MUTEX_INIT(a,b,c,d)     lock_alloc((void*)(a), LOCK_ALLOC_PIN, 1, 1), \
00053                                 simple_lock_init((void *)(a))
00054 #define MUTEX_DESTROY(a)        lock_free((void*)(a))
00055 
00056 #ifdef RX_LOCKS_DB
00057 
00058 #define MUTEX_ENTER(a)          simple_lock((void *)(a)), \
00059                                 rxdb_grablock((void *)(a), thread_self(),rxdb_fileID,\
00060                                               __LINE__)
00061 
00062 #define MUTEX_TRYENTER(a)       (simple_lock_try((void *)(a)) ?\
00063                                 rxdb_grablock((void *)(a), thread_self(), rxdb_fileID,\
00064                                               __LINE__), 1 : 0)
00065 
00066 #define MUTEX_EXIT(a)           rxdb_droplock((void *)(a), thread_self(), rxdb_fileID,\
00067                                               __LINE__), \
00068                                 simple_unlock((void *)(a))
00069 
00070 #define CV_WAIT(_cv, _lck) \
00071     do { \
00072         int haveGlock = ISAFS_GLOCK(); \
00073         if (haveGlock) \
00074             AFS_GUNLOCK(); \
00075         rxdb_droplock((void *)(_lck), thread_self(), rxdb_fileID, __LINE__); \
00076         e_sleep_thread((_cv), (_lck), LOCK_SIMPLE); \
00077         rxdb_grablock((void *)(_lck), thread_self(), rxdb_fileID, __LINE__); \
00078         if (haveGlock) { \
00079             MUTEX_EXIT(_lck); \
00080             AFS_GLOCK(); \
00081             MUTEX_ENTER(_lck); \
00082         } \
00083     } while(0)
00084 
00085 #define CV_TIMEDWAIT(_cv, _lck, _t) \
00086     do { \
00087         int haveGlock = ISAFS_GLOCK(); \
00088         if (haveGlock) \
00089             AFS_GUNLOCK(); \
00090         rxdb_droplock((void *)(_lck), thread_self(), rxdb_fileID, __LINE__); \
00091         e_mpsleep((_cv), (_t), (_lck), LOCK_SIMPLE); \
00092         rxdb_grablock((void *)(_lck), thread_self(), rxdb_fileID, __LINE__); \
00093         if (haveGlock) { \
00094             MUTEX_EXIT(_lck); \
00095             AFS_GLOCK(); \
00096             MUTEX_ENTER(_lck); \
00097         } \
00098     } while(0)
00099 
00100 #else /* RX_LOCK_DB */
00101 
00102 #define MUTEX_ENTER(a)          simple_lock((void *)(a))
00103 #define MUTEX_TRYENTER(a)       simple_lock_try((void *)(a))
00104 #define MUTEX_EXIT(a)           simple_unlock((void *)(a))
00105 
00106 #define CV_WAIT(_cv, _lck) \
00107     do { \
00108         int haveGlock = ISAFS_GLOCK(); \
00109         if (haveGlock) \
00110             AFS_GUNLOCK(); \
00111         e_sleep_thread((_cv), (_lck), LOCK_SIMPLE); \
00112         if (haveGlock) { \
00113             MUTEX_EXIT(_lck); \
00114             AFS_GLOCK(); \
00115             MUTEX_ENTER(_lck); \
00116         } \
00117     } while(0)
00118 
00119 #define CV_TIMEDWAIT(_cv, _lck, _t) \
00120     do { \
00121         int haveGlock = ISAFS_GLOCK(); \
00122         if (haveGlock) \
00123             AFS_GUNLOCK(); \
00124         e_mpsleep((_cv), (_t), (_lck), LOCK_SIMPLE); \
00125         if (haveGlock) { \
00126             MUTEX_EXIT(_lck); \
00127             AFS_GLOCK(); \
00128             MUTEX_ENTER(_lck); \
00129         } \
00130     } while(0)
00131 
00132 #endif /* RX_LOCK_DB */
00133 
00134 #define MUTEX_DEFAULT   0
00135 
00136 #undef MUTEX_ISMINE
00137 #define MUTEX_ISMINE(a) (lock_mine((void *)(a)))
00138 
00139 #undef osirx_AssertMine
00140 extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
00141 
00142 #endif /* AFS_AIX41_ENV */
00143 
00144 #endif /* _RX_KMUTEX_H_ */
 All Data Structures Files Functions Variables