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