Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / rx / NBSD / rx_kmutex.c
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.c - mutex and condition variable macros for kernel environment.
12 *
13 * NetBSD implementation.
14 */
15
16 #include <afsconfig.h>
17 #include "afs/param.h"
18
19 #if defined(AFS_NBSD50_ENV)
20
21 #include "rx/rx_kcommon.h"
22 #include "rx_kmutex.h"
23 #include "rx/rx_kernel.h"
24
25 int
26 afs_cv_wait(afs_kcondvar_t *cv, afs_kmutex_t *m, int sigok)
27 {
28 int haveGlock = ISAFS_GLOCK();
29 int retval = 0;
30
31 if (haveGlock)
32 AFS_GUNLOCK();
33 if (sigok) {
34 if (cv_wait_sig(cv, m) == 0)
35 retval = EINTR;
36 } else {
37 cv_wait(cv, m);
38 }
39 if (haveGlock) {
40 MUTEX_EXIT(m);
41 AFS_GLOCK();
42 MUTEX_ENTER(m);
43 }
44 return retval;
45 }
46
47 int
48 afs_cv_timedwait(afs_kcondvar_t *cv, afs_kmutex_t *m, int t, int sigok)
49 {
50 int haveGlock = ISAFS_GLOCK();
51 int retval = 0;
52
53 if (haveGlock)
54 AFS_GUNLOCK();
55 if (sigok) {
56 if (cv_timedwait_sig(cv, m, t) == 0)
57 retval = EINTR;
58 } else {
59 cv_timedwait(cv, m, t);
60 }
61 if (haveGlock) {
62 MUTEX_EXIT(m);
63 AFS_GLOCK();
64 MUTEX_ENTER(m);
65 }
66 return retval;
67 }
68
69 #endif /* AFS_NBSD50_ENV */