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