Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / rx / SOLARIS / 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 * Solaris implementation.
14 */
15
16 #include <afsconfig.h>
17 #include "afs/param.h"
18
19
20 #if defined(AFS_SUN5_ENV) && defined(KERNEL)
21
22 #include "rx/rx_kcommon.h"
23 #include "rx_kmutex.h"
24 #include "rx/rx_kernel.h"
25
26 #include <errno.h>
27 #include <sys/tiuser.h>
28 #include <sys/t_lock.h>
29 #include <sys/mutex.h>
30
31 #ifdef RX_LOCKS_DB
32 int
33 afs_cv_wait(cv, m, sigok, fileid, line)
34 int fileid;
35 int line;
36 #else
37 int
38 afs_cv_wait(cv, m, sigok)
39 #endif
40 afs_kcondvar_t *cv;
41 afs_kmutex_t *m;
42 int sigok;
43 {
44 int haveGlock = ISAFS_GLOCK();
45 int retval = 0;
46
47 if (haveGlock)
48 AFS_GUNLOCK();
49 #ifdef RX_LOCKS_DB
50 rxdb_droplock(m, osi_ThreadUnique(), fileid, line);
51 #endif
52 if (sigok) {
53 if (cv_wait_sig(cv, m) == 0)
54 retval = EINTR;
55 } else {
56 cv_wait(cv, m);
57 }
58 #ifdef RX_LOCKS_DB
59 rxdb_grablock(m, osi_ThreadUnique(), fileid, line);
60 #endif
61 if (haveGlock) {
62 MUTEX_EXIT(m);
63 AFS_GLOCK();
64 MUTEX_ENTER(m);
65 }
66 return retval;
67 }
68
69 #ifdef RX_LOCKS_DB
70 int
71 afs_cv_timedwait(cv, m, t, sigok, fileid, line)
72 int fileid;
73 int line;
74 #else
75 int
76 afs_cv_timedwait(cv, m, t, sigok)
77 #endif
78 afs_kcondvar_t *cv;
79 afs_kmutex_t *m;
80 clock_t t;
81 int sigok;
82 {
83 int haveGlock = ISAFS_GLOCK();
84 int retval = 0;
85
86 if (haveGlock)
87 AFS_GUNLOCK();
88 #ifdef RX_LOCKS_DB
89 rxdb_droplock(m, osi_ThreadUnique(), fileid, line);
90 #endif
91 if (sigok) {
92 if (cv_timedwait_sig(cv, m, t) == 0)
93 retval = EINTR;
94 } else {
95 cv_timedwait(cv, m, t);
96 }
97 #ifdef RX_LOCKS_DB
98 rxdb_grablock(m, osi_ThreadUnique(), fileid, line);
99 #endif
100 if (haveGlock) {
101 MUTEX_EXIT(m);
102 AFS_GLOCK();
103 MUTEX_ENTER(m);
104 }
105 return retval;
106 }
107
108 #endif /* SUN5 && KERNEL */