2 * Copyright 2000, International Business Machines Corporation and others.
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
11 * rx_kmutex.h - mutex and condition variable macros for kernel environment.
13 * AIX 4.x implementation.
23 #include <sys/lockl.h>
24 #include <sys/lock_def.h>
25 #include <sys/lock_alloc.h>
26 #include <sys/sleep.h>
27 #define RX_ENABLE_LOCKS 1
28 #define AFS_GLOBAL_RXLOCK_KERNEL
30 * `condition variables' -- well, not really. these just map to the
31 * AIX event-list routines. Thus, if one signals a condition prior to
32 * a process waiting for it, the signal gets lost.
34 * `t' in `cv_timedwait' has different interpretation
40 #define MUTEX_DEFAULT 0
42 #define CV_INIT(cv, a,b,c) (*(cv) = EVENT_NULL)
43 #define CV_DESTROY(cv)
44 #define CV_SIGNAL(_cv) e_wakeup_one(_cv)
45 #define CV_BROADCAST(_cv) e_wakeup(_cv)
46 typedef simple_lock_data afs_kmutex_t;
47 typedef tid_t afs_kcondvar_t;
48 #define osi_rxWakeup(cv) e_wakeup(cv)
51 #define LOCK_INIT(a, b) lock_alloc((void*)(a), LOCK_ALLOC_PIN, 1, 1), \
52 simple_lock_init((void *)(a))
53 #define MUTEX_INIT(a,b,c,d) lock_alloc((void*)(a), LOCK_ALLOC_PIN, 1, 1), \
54 simple_lock_init((void *)(a))
55 #define MUTEX_DESTROY(a) lock_free((void*)(a))
59 #define MUTEX_ENTER(a) simple_lock((void *)(a)), \
60 rxdb_grablock((void *)(a), thread_self(),rxdb_fileID,\
63 #define MUTEX_TRYENTER(a) (simple_lock_try((void *)(a)) ?\
64 rxdb_grablock((void *)(a), thread_self(), rxdb_fileID,\
67 #define MUTEX_EXIT(a) rxdb_droplock((void *)(a), thread_self(), rxdb_fileID,\
69 simple_unlock((void *)(a))
72 #define RXObtainWriteLock(a) simple_lock((void *)(a)), \
73 rxdb_grablock((void *)(a), thread_self(),rxdb_fileID,\
76 #define RXReleaseWriteLock(a) rxdb_droplock((void *)(a), thread_self(), rxdb_fileID,\
78 simple_unlock((void *)(a))
80 #define CV_WAIT(_cv, _lck) \
82 int haveGlock = ISAFS_GLOCK(); \
85 rxdb_droplock((void *)(_lck), thread_self(), rxdb_fileID, __LINE__); \
86 e_sleep_thread((_cv), (_lck), LOCK_SIMPLE); \
87 rxdb_grablock((void *)(_lck), thread_self(), rxdb_fileID, __LINE__); \
95 #define CV_TIMEDWAIT(_cv, _lck, _t) \
97 int haveGlock = ISAFS_GLOCK(); \
100 rxdb_droplock((void *)(_lck), thread_self(), rxdb_fileID, __LINE__); \
101 e_mpsleep((_cv), (_t), (_lck), LOCK_SIMPLE); \
102 rxdb_grablock((void *)(_lck), thread_self(), rxdb_fileID, __LINE__); \
110 #else /* RX_LOCK_DB */
112 #define MUTEX_ENTER(a) simple_lock((void *)(a))
113 #define MUTEX_TRYENTER(a) simple_lock_try((void *)(a))
114 #define MUTEX_EXIT(a) simple_unlock((void *)(a))
115 #define RXObtainWriteLock(a) simple_lock((void *)(a))
116 #define RXReleaseWriteLock(a) simple_unlock((void *)(a))
118 #define CV_WAIT(_cv, _lck) \
120 int haveGlock = ISAFS_GLOCK(); \
123 e_sleep_thread((_cv), (_lck), LOCK_SIMPLE); \
131 #define CV_TIMEDWAIT(_cv, _lck, _t) \
133 int haveGlock = ISAFS_GLOCK(); \
136 e_mpsleep((_cv), (_t), (_lck), LOCK_SIMPLE); \
144 #endif /* RX_LOCK_DB */
146 #define MUTEX_DEFAULT 0
149 #define MUTEX_ISMINE(a) (lock_mine((void *)(a)))
151 #undef osirx_AssertMine
152 extern void osirx_AssertMine(afs_kmutex_t *lockaddr, char *msg);
154 #endif /* AFS_AIX41_ENV */
156 #endif /* _RX_KMUTEX_H_ */