First pass at better signal handling:
[openafs.git] / src / rx / FBSD / rx_kmutex.h
1 /* Copyright Transarc Corporation 1998 - All Rights Reserved
2  *
3  * rx_kmutex.h - mutex and condition variable macros for kernel environment.
4  *
5  * DUX implementation.
6  */
7
8 #ifndef _RX_KMUTEX_H_
9 #define _RX_KMUTEX_H_
10
11 #ifdef AFS_FBSD40_ENV
12
13 #include <sys/lock.h>
14 /* #include <kern/sched_prim.h> */
15 /* #include <sys/unix_defs.h> */
16
17 #define RX_ENABLE_LOCKS         1
18 #define AFS_GLOBAL_RXLOCK_KERNEL
19
20 /*
21  * Condition variables
22  *
23  * In Digital Unix (OSF/1), we use something akin to the ancient sleep/wakeup
24  * mechanism.  The condition variable itself plays no role; we just use its
25  * address as a convenient unique number.
26  */
27 #define CV_INIT(cv,a,b,c)
28 #define CV_DESTROY(cv)
29 #define CV_WAIT(cv, lck)    { \
30                                 int isGlockOwner = ISAFS_GLOCK(); \
31                                 if (isGlockOwner) AFS_GUNLOCK();  \
32                                 assert_wait((vm_offset_t)(cv), 0);      \
33                                 MUTEX_EXIT(lck);        \
34                                 thread_block();         \
35                                 if (isGlockOwner) AFS_GLOCK();  \
36                                 MUTEX_ENTER(lck); \
37                             }
38
39 #define CV_TIMEDWAIT(cv,lck,t)  { \
40                                 int isGlockOwner = ISAFS_GLOCK(); \
41                                 if (isGlockOwner) AFS_GUNLOCK();  \
42                                 assert_wait((vm_offset_t)(cv), 0);      \
43                                 thread_set_timeout(t);  \
44                                 MUTEX_EXIT(lck);        \
45                                 thread_block();         \
46                                 if (isGlockOwner) AFS_GLOCK();  \
47                                 MUTEX_ENTER(lck);       \
48                                 }
49
50 #define CV_SIGNAL(cv)           thread_wakeup_one((vm_offset_t)(cv))
51 #define CV_BROADCAST(cv)        thread_wakeup((vm_offset_t)(cv))
52
53 typedef struct {
54     struct simplelock lock;
55 } afs_kmutex_t;
56 typedef int afs_kcondvar_t;
57
58 #define osi_rxWakeup(cv)        thread_wakeup((vm_offset_t)(cv))
59
60 #define LOCK_INIT(a,b) \
61     do { \
62         usimple_lock_init(&(a)->lock); \
63     } while(0);
64 #define MUTEX_INIT(a,b,c,d) \
65     do { \
66         usimple_lock_init(&(a)->lock); \
67     } while(0);
68 #define MUTEX_DESTROY(a) \
69     do { \
70         usimple_lock_terminate(&(a)->lock); \
71     } while(0);
72 #define MUTEX_ENTER(a) \
73     do { \
74         usimple_lock(&(a)->lock); \
75     } while(0);
76 #define MUTEX_TRYENTER(a) \
77    usimple_lock(&(a)->lock)
78 #define MUTEX_EXIT(a) \
79     do { \
80         usimple_unlock(&(a)->lock); \
81     } while(0);
82
83 #undef MUTEX_ISMINE
84 #define MUTEX_ISMINE(a) 1
85 /* 
86   #define MUTEX_ISMINE(a) 
87   (((afs_kmutex_t *)(a))->owner == current_thread())
88 */ 
89
90 #undef osirx_AssertMine
91 extern void osirx_AssertMine(afs_kmutex_t *lockaddr, char *msg);
92
93 #endif  /* FBSD40 */
94
95
96 #endif /* _RX_KMUTEX_H_ */
97