initial-freebsd-port-work-20010414
[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 #define CV_SIGNAL(cv)           thread_wakeup_one((vm_offset_t)(cv))
50 #define CV_BROADCAST(cv)        thread_wakeup((vm_offset_t)(cv))
51
52 typedef struct {
53     struct simplelock lock;
54 } afs_kmutex_t;
55 typedef int afs_kcondvar_t;
56
57 #define osi_rxWakeup(cv)        thread_wakeup((vm_offset_t)(cv))
58
59 #define LOCK_INIT(a,b) \
60     do { \
61         usimple_lock_init(&(a)->lock); \
62     } while(0);
63 #define MUTEX_INIT(a,b,c,d) \
64     do { \
65         usimple_lock_init(&(a)->lock); \
66     } while(0);
67 #define MUTEX_DESTROY(a) \
68     do { \
69         usimple_lock_terminate(&(a)->lock); \
70     } while(0);
71 #define MUTEX_ENTER(a) \
72     do { \
73         usimple_lock(&(a)->lock); \
74     } while(0);
75 #define MUTEX_TRYENTER(a) \
76    usimple_lock(&(a)->lock)
77 #define MUTEX_EXIT(a) \
78     do { \
79         usimple_unlock(&(a)->lock); \
80     } while(0);
81
82 #undef MUTEX_ISMINE
83 #define MUTEX_ISMINE(a) 1
84 /* 
85   #define MUTEX_ISMINE(a) 
86   (((afs_kmutex_t *)(a))->owner == current_thread())
87 */ 
88
89 #undef osirx_AssertMine
90 extern void osirx_AssertMine(afs_kmutex_t *lockaddr, char *msg);
91
92 #endif  /* FBSD40 */
93
94
95 #endif /* _RX_KMUTEX_H_ */
96