death to trailing whitespace
[openafs.git] / src / rx / OBSD / 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 /*
11  * rx_kmutex.h - mutex and condition variable macros for kernel environment.
12  *
13  * OpenBSD implementation by Jim Rees.
14  */
15
16 #ifndef _RX_KMUTEX_H_
17 #define _RX_KMUTEX_H_
18
19 #include <sys/lock.h>
20
21 /* You can't have AFS_GLOBAL_SUNLOCK and not RX_ENABLE_LOCKS */
22 #define RX_ENABLE_LOCKS 1
23 #define AFS_GLOBAL_RXLOCK_KERNEL
24
25 /* This is incomplete and probably wouldn't work with NCPUS > 1 */
26
27 typedef int afs_kcondvar_t;
28
29 #define CV_INIT(cv, a, b, c)
30 #define CV_DESTROY(cv)
31 #define CV_WAIT(cv, lck)    { \
32                                 int isGlockOwner = ISAFS_GLOCK(); \
33                                 if (isGlockOwner) AFS_GUNLOCK();  \
34                                 MUTEX_EXIT(lck);        \
35                                 tsleep(cv, PSOCK, "afs_rx_cv_wait", 0);  \
36                                 if (isGlockOwner) AFS_GLOCK();  \
37                                 MUTEX_ENTER(lck); \
38                             }
39 #define CV_SIGNAL(cv)           wakeup_one(cv)
40 #define CV_BROADCAST(cv)        wakeup(cv)
41
42 typedef struct {
43     struct proc *owner;
44 } afs_kmutex_t;
45
46 #define MUTEX_DEFAULT   0
47
48 #define MUTEX_INIT(a,b,c,d) \
49     do { \
50         (a)->owner = 0; \
51     } while(0);
52 #define MUTEX_DESTROY(a) \
53     do { \
54         (a)->owner = (struct proc *)-1; \
55     } while(0);
56 #define MUTEX_ENTER(a) \
57     do { \
58         osi_Assert((a)->owner == 0); \
59         (a)->owner = curproc; \
60     } while(0);
61 #define MUTEX_TRYENTER(a) \
62     ( osi_Assert((a)->owner == 0), (a)->owner = curproc, 1)
63 #define MUTEX_EXIT(a) \
64     do { \
65         osi_Assert((a)->owner == curproc); \
66         (a)->owner = 0; \
67     } while(0);
68 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == curproc)
69
70 #endif /* _RX_KMUTEX_H_ */