hpux-rx-kmutex-h-20020926
[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_sync.h>
24 #include <sys/errno.h>
25 #include <net/netmp.h>
26
27 #define RX_ENABLE_LOCKS         1
28 #define AFS_GLOBAL_RXLOCK_KERNEL
29 extern lock_t*  rx_sleepLock;
30
31 #define CV_INIT(cv,a,b,c) 
32
33 /* this is supposed to atomically drop the mutex and go to sleep */
34 /* reacquire the mutex when the sleep is done */
35 #define CV_WAIT(cv, lck) {                                                \
36                           int code;                                       \
37                           ksleep_prepare();                               \
38                           MP_SPINLOCK(rx_sleepLock);                      \
39                           if (valusync(lck) < 1)                          \
40                                 vsync(lck);                               \
41                           else                                            \
42                                 osi_Panic("mutex not held %d",valusync(lck)); \
43                           code=ksleep_one(KERNEL_ADDRESS|KERN_SPINLOCK_OBJECT,\
44                                         (cv),rx_sleepLock,0);             \
45                           if ( code ) {                                   \
46                               if ( code == EINTR ) {/* lock still held */ \
47                                   MP_SPINUNLOCK(rx_sleepLock);            \
48                               } else if (code != -EINTR) {                \
49                                   osi_Panic("ksleep_one failed %d", code);\
50                               }                                           \
51                           }                                               \
52                           psync(lck); /* grab the mutex again */          \
53                         }
54
55 /* Wakes up one thread waiting on this condition */
56 #define CV_SIGNAL(cv)    {                                                \
57                            int wo, code;                                  \
58                            MP_SPINLOCK(rx_sleepLock);                     \
59                            if( (code = kwakeup_one(KERNEL_ADDRESS,(cv),   \
60                                                   WAKEUP_ONE, &wo))<0)    \
61                                 osi_Panic("kwakeup_one failed %d", code); \
62                            MP_SPINUNLOCK(rx_sleepLock);                   \
63                          }
64
65 /* wakeup all threads waiting on this condition */
66 #define CV_BROADCAST(cv) {                                                \
67                            int wo, code;                                  \
68                            MP_SPINLOCK(rx_sleepLock);                     \
69                            if( (code = kwakeup_one(KERNEL_ADDRESS,(cv),   \
70                                                  WAKEUP_ALL, &wo))<0)     \
71                                 osi_Panic("kwakeup_all failed %d", code); \
72                            MP_SPINUNLOCK(rx_sleepLock);                   \
73                          }
74
75 typedef sync_t  afs_kmutex_t;
76 typedef caddr_t afs_kcondvar_t;
77
78 #else /* AFS_HPUX110_ENV */
79
80 #if defined(AFS_HPUX102_ENV)
81 #define CV_INIT(a,b,c,d)
82 #define CV_DESTROY(a)
83 #endif /* AFS_HPUX102_ENV */
84 #endif /* else AFS_HPUX110_ENV */
85
86 #ifdef AFS_HPUX102_ENV
87
88 #define RXObtainWriteLock(a) AFS_ASSERT_RXGLOCK()
89 #define RXReleaseWriteLock(a)
90
91
92 #if defined(AFS_HPUX110_ENV) 
93 #undef osirx_AssertMine
94 extern void osirx_AssertMine(afs_kmutex_t *lockaddr, char *msg);
95
96 #define MUTEX_DESTROY(a)        ( dealloc_spinlock((a)->s_lock) )
97 #define MUTEX_ENTER(a)          psync(a)
98 #define MUTEX_TRYENTER(a)       ( (valusync(a)==1)? (MUTEX_ENTER(a), 1):0 )
99 #define MUTEX_EXIT(a)           ((valusync(a)<1)? vsync(a) : \
100                                                 osi_Panic("mutex not held"))
101 #define MUTEX_INIT(a,b,c,d)     (initsync(a), vsync(a))
102
103 #undef MUTEX_ISMINE
104 #define MUTEX_ISMINE(a)         ( (valusync(a)<1) ? 1 : 0 ) 
105
106 #else /* AFS_HPUX110_ENV */
107
108 #define osirx_AssertMine(addr, msg)
109
110 #define MUTEX_DESTROY(a)
111 #define MUTEX_ENTER(a)
112 #define MUTEX_TRYENTER(a) 1
113 #define MUTEX_EXIT(a)  
114 #define MUTEX_INIT(a,b,c,d) 
115
116 #endif /* else AFS_HPUX110_ENV */
117 #endif /* AFS_HPUX102_ENV */
118 #endif /* _RX_KMUTEX_H_ */
119