Import Upstream version 1.8.5
[hcoop/debian/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
24 /* This is incomplete and probably wouldn't work with NCPUS > 1 */
25
26 typedef int afs_kcondvar_t;
27
28 #define CV_INIT(cv, a, b, c)
29 #define CV_DESTROY(cv)
30 #define CV_WAIT(cv, lck) { \
31 int isGlockOwner = ISAFS_GLOCK(); \
32 if (isGlockOwner) AFS_GUNLOCK(); \
33 MUTEX_EXIT(lck); \
34 tsleep(cv, PSOCK, "afs_rx_cv_wait", 0); \
35 if (isGlockOwner) AFS_GLOCK(); \
36 MUTEX_ENTER(lck); \
37 }
38 #define CV_SIGNAL(cv) wakeup_one(cv)
39 #define CV_BROADCAST(cv) wakeup(cv)
40
41 typedef struct {
42 struct proc *owner;
43 } afs_kmutex_t;
44
45 #define MUTEX_DEFAULT 0
46
47 #define MUTEX_INIT(a,b,c,d) \
48 do { \
49 (a)->owner = 0; \
50 } while(0);
51 #define MUTEX_DESTROY(a) \
52 do { \
53 (a)->owner = (struct proc *)-1; \
54 } while(0);
55 #define MUTEX_ENTER(a) \
56 do { \
57 osi_Assert((a)->owner == 0); \
58 (a)->owner = curproc; \
59 } while(0);
60 #define MUTEX_TRYENTER(a) \
61 ( osi_Assert((a)->owner == 0), (a)->owner = curproc, 1)
62 #define MUTEX_EXIT(a) \
63 do { \
64 osi_Assert((a)->owner == curproc); \
65 (a)->owner = 0; \
66 } while(0);
67 #define MUTEX_ASSERT(a) osi_Assert(((afs_kmutex_t *)(a))->owner == curproc)
68
69 #endif /* _RX_KMUTEX_H_ */