venus: Remove dedebug
[openafs.git] / src / rx / HPUX / rx_kmutex.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  */
9
10 /* rx_kmutex.h - mutex and condition variable macros for kernel environment.
11  *
12  * HPUX implementation.
13  */
14
15 #ifndef _RX_KMUTEX_H_
16 #define _RX_KMUTEX_H_
17
18 #if defined(AFS_HPUX110_ENV) && defined(KERNEL)
19 /* rx fine grain locking primitives */
20
21 #include <sys/ksleep.h>
22 #include <sys/spinlock.h>
23 #include <sys/sem_beta.h>
24 #include <sys/errno.h>
25 #include <net/netmp.h>
26
27 #include "../rx/rx_kernel.h"    /* For osi_Panic() */
28
29 #define RX_ENABLE_LOCKS         1
30
31 extern lock_t *rx_sleepLock;
32
33 /* We use beta semaphores instead of sync semaphores for Rx locks as
34  * recommended by HP labs. Sync semaphores are not supported by HP
35  * any more.
36  */
37
38 #define CV_INIT(cv,a,b,c)
39
40 /* This is supposed to atomically drop the mutex and go to sleep
41  * and reacquire the mutex when it wakes up.
42  */
43
44 /* With 11.23, ksleep_prepare is not defined anywhere  and
45  * ksleep_one is only referenced in a comment. sleep, get_sleep_lock
46  * and wakeup are defined in driver manuals.
47  * This works with 11.0, 11i, and 11.23
48  * Note: wakeup wakes up all threads waiting on cv.
49  */
50
51 #define CV_WAIT(cv, lck) \
52         do { \
53                 get_sleep_lock((caddr_t)(cv)); \
54                 if (!b_owns_sema(lck)) \
55                         osi_Panic("CV_WAIT mutex not held \n"); \
56                 b_vsema(lck);   \
57                 sleep((caddr_t)(cv), PRIBIO); \
58                 b_psema(lck); \
59         } while(0)
60
61 #define CV_SIGNAL(cv)  \
62         do { \
63                 lock_t * sleep_lock = get_sleep_lock((caddr_t)(cv)); \
64                 wakeup((caddr_t)(cv)); \
65                 spinunlock(sleep_lock); \
66         } while(0)
67
68 #define CV_BROADCAST(cv) \
69         do { \
70                 lock_t * sleep_lock = get_sleep_lock((caddr_t)(cv)); \
71                 wakeup((caddr_t)(cv)); \
72                 spinunlock(sleep_lock); \
73         } while(0)
74
75
76 #define CV_DESTROY(a)
77
78 /* We now use beta semaphores for mutexes */
79 typedef b_sema_t afs_kmutex_t;
80 typedef caddr_t afs_kcondvar_t;
81
82 #else /* AFS_HPUX110_ENV */
83
84 #if defined(AFS_HPUX102_ENV)
85 #define CV_INIT(a,b,c,d)
86 #define CV_DESTROY(a)
87 #endif /* AFS_HPUX102_ENV */
88 #endif /* else AFS_HPUX110_ENV */
89
90 #ifdef AFS_HPUX102_ENV
91
92 #if defined(AFS_HPUX110_ENV)
93
94 #define AFS_RX_ORDER 30
95
96 #define MUTEX_INIT(a,b,c,d) b_initsema((a), 1, AFS_RX_ORDER, (b))
97 #define MUTEX_DESTROY(a)
98
99 #define MUTEX_TRYENTER(a) b_cpsema(a)
100
101 #ifdef AFS_HPUX1111_ENV
102 #define MUTEX_ENTER(a) \
103         ((b_owns_sema(a)) ? osi_Panic("Already Held") : b_psema(a))
104 #define MUTEX_EXIT(a) \
105         ((b_owns_sema(a)) ? b_vsema(a) : osi_Panic("mutex not held"))
106 #else
107 #define MUTEX_ENTER(a) \
108     ((b_owns_sema(a)) ? (osi_Panic("Already Held"), 0) : b_psema(a))
109
110 #define MUTEX_EXIT(a) \
111     ((b_owns_sema(a)) ? b_vsema(a) : (osi_Panic("mutex not held"), 0))
112 #endif
113
114 #define MUTEX_ASSERT(a) osi_Assert(b_owns_sema(a))
115
116 #else /* AFS_HPUX110_ENV */
117
118 #define MUTEX_DESTROY(a)
119 #define MUTEX_ENTER(a)
120 #define MUTEX_TRYENTER(a) 1
121 #define MUTEX_EXIT(a)
122 #define MUTEX_INIT(a,b,c,d)
123 #define MUTEX_ASSERT(a)
124
125 #endif /* else AFS_HPUX110_ENV */
126 #endif /* AFS_HPUX102_ENV */
127 #endif /* _RX_KMUTEX_H_ */