Print this page
8115 parallel zfs mount
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libfakekernel/common/cond.c
+++ new/usr/src/lib/libfakekernel/common/cond.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 13 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
14 + * Copyright 2017 RackTop Systems.
14 15 */
15 16
16 17 /*
17 18 * condvar(9f)
18 19 */
19 20
20 21 /* This is the API we're emulating */
21 22 #include <sys/condvar.h>
22 23
23 24 #include <sys/errno.h>
24 25 #include <sys/debug.h>
25 26 #include <sys/thread.h>
26 27
27 28 /* avoiding synch.h */
28 29 int _lwp_cond_wait(lwp_cond_t *, lwp_mutex_t *);
29 30 int _lwp_cond_timedwait(lwp_cond_t *, lwp_mutex_t *, timespec_t *);
30 31 int _lwp_cond_reltimedwait(lwp_cond_t *, lwp_mutex_t *, timespec_t *);
31 32 int _lwp_cond_signal(lwp_cond_t *);
32 33 int _lwp_cond_broadcast(lwp_cond_t *);
33 34
34 35
35 36 extern clock_t ddi_get_lbolt(void);
36 37 extern void clock2ts(clock_t, timespec_t *);
37 38
38 39 static int cv__wait(kcondvar_t *, kmutex_t *, int);
39 40 static clock_t cv__twait(kcondvar_t *, kmutex_t *, clock_t, int);
40 41
41 42 static const lwp_cond_t default_cv =
42 43 {{{0, 0, 0, 0}, USYNC_THREAD, _COND_MAGIC}, 0};
43 44
44 45
45 46 /* ARGSUSED */
46 47 void
47 48 cv_init(kcondvar_t *cv, char *name, kcv_type_t typ, void *arg)
48 49 {
49 50 *cv = default_cv;
50 51 }
51 52
52 53 /* ARGSUSED */
53 54 void
54 55 cv_destroy(kcondvar_t *cv)
55 56 {
56 57 }
57 58
58 59 void
59 60 cv_signal(kcondvar_t *cv)
60 61 {
61 62 (void) _lwp_cond_signal(cv);
62 63 }
63 64
64 65 void
65 66 cv_broadcast(kcondvar_t *cv)
66 67 {
67 68 (void) _lwp_cond_broadcast(cv);
68 69 }
69 70
70 71 void
71 72 cv_wait(kcondvar_t *cv, kmutex_t *mp)
72 73 {
73 74 (void) cv__wait(cv, mp, 0);
74 75 }
75 76
76 77 int
77 78 cv_wait_sig(kcondvar_t *cv, kmutex_t *mp)
78 79 {
79 80 return (cv__wait(cv, mp, 1));
80 81 }
81 82
82 83 int
83 84 cv__wait(kcondvar_t *cv, kmutex_t *mp, int sigok)
84 85 {
85 86 int err;
86 87
87 88 top:
88 89 ASSERT(mp->m_owner == _curthread());
89 90 mp->m_owner = _KTHREAD_INVALID;
90 91 err = _lwp_cond_wait(cv, &mp->m_lock);
91 92 mp->m_owner = _curthread();
92 93
93 94 if (err == 0)
94 95 return (1);
95 96 if (err == EINTR) {
96 97 if (sigok)
97 98 return (0);
98 99 goto top;
99 100 }
100 101 return (-1);
101 102 }
102 103
103 104 clock_t
104 105 cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime)
105 106 {
106 107 clock_t delta;
107 108
108 109 delta = abstime - ddi_get_lbolt();
109 110 return (cv__twait(cv, mp, delta, 0));
110 111 }
↓ open down ↓ |
87 lines elided |
↑ open up ↑ |
111 112
112 113 clock_t
113 114 cv_timedwait_sig(kcondvar_t *cv, kmutex_t *mp, clock_t abstime)
114 115 {
115 116 clock_t delta;
116 117
117 118 delta = abstime - ddi_get_lbolt();
118 119 return (cv__twait(cv, mp, delta, 1));
119 120 }
120 121
122 +/*ARGSUSED*/
123 +clock_t
124 +cv_timedwait_hires(kcondvar_t *cv, kmutex_t *mp, hrtime_t tim, hrtime_t res,
125 + int flag)
126 +{
127 + clock_t delta;
128 +
129 + delta = tim;
130 + if (flag & CALLOUT_FLAG_ABSOLUTE)
131 + delta -= gethrtime();
132 + return (cv__twait(cv, mp, delta, 0));
133 +}
134 +
121 135 clock_t
122 136 cv_reltimedwait(kcondvar_t *cv, kmutex_t *mp, clock_t delta, time_res_t res)
123 137 {
124 138 _NOTE(ARGUNUSED(res))
125 139
126 140 return (cv__twait(cv, mp, delta, 0));
127 141 }
128 142
129 143 clock_t
130 144 cv_reltimedwait_sig(kcondvar_t *cv, kmutex_t *mp, clock_t delta,
131 145 time_res_t res)
132 146 {
133 147 _NOTE(ARGUNUSED(res))
134 148
135 149 return (cv__twait(cv, mp, delta, 1));
136 150 }
137 151
138 152 /*
139 153 * Factored out implementation of all the cv_*timedwait* functions.
140 154 * Note that the delta passed in is relative to the (simulated)
141 155 * current time reported by ddi_get_lbolt(). Convert that to
142 156 * timespec format and keep calling _lwp_cond_reltimedwait,
143 157 * which (NB!) decrements that delta in-place!
144 158 */
145 159 static clock_t
146 160 cv__twait(kcondvar_t *cv, kmutex_t *mp, clock_t delta, int sigok)
147 161 {
148 162 timestruc_t ts;
149 163 int err;
150 164
151 165 if (delta <= 0)
152 166 return (-1);
153 167
154 168 clock2ts(delta, &ts);
155 169
156 170 top:
157 171 if (ts.tv_sec == 0 && ts.tv_nsec == 0)
158 172 return (-1);
159 173
160 174 ASSERT(mp->m_owner == _curthread());
161 175 mp->m_owner = _KTHREAD_INVALID;
162 176 err = _lwp_cond_reltimedwait(cv, &mp->m_lock, &ts);
163 177 mp->m_owner = _curthread();
164 178
165 179 switch (err) {
166 180 case 0:
167 181 return (1);
168 182 case EINTR:
169 183 if (sigok)
170 184 return (0);
171 185 goto top;
172 186 default:
173 187 ASSERT(0);
174 188 /* FALLTHROUGH */
175 189 case ETIME:
176 190 break;
177 191 }
178 192
179 193 return (-1);
180 194 }
↓ open down ↓ |
50 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX