rumpuser_pth_dummy.c revision 1.13 1 /* $NetBSD: rumpuser_pth_dummy.c,v 1.13 2013/05/02 19:14:59 pooka Exp $ */
2
3 /*
4 * Copyright (c) 2009 Antti Kantee. All Rights Reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #include "rumpuser_port.h"
29
30 #include <sys/cdefs.h>
31 #if !defined(lint)
32 __RCSID("$NetBSD: rumpuser_pth_dummy.c,v 1.13 2013/05/02 19:14:59 pooka Exp $");
33 #endif /* !lint */
34
35 #include <sys/time.h>
36
37 #include <assert.h>
38 #include <errno.h>
39 #include <stdlib.h>
40 #include <stdio.h>
41 #include <string.h>
42 #include <stdint.h>
43
44 #include <rump/rumpuser.h>
45
46 #include "rumpuser_int.h"
47
48 static struct lwp *curlwp;
49
50 struct rumpuser_cv {};
51
52 struct rumpuser_mtx {
53 int v;
54 struct lwp *o;
55 };
56
57 struct rumpuser_rw {
58 int v;
59 };
60
61 void
62 rumpuser__thrinit(void)
63 {
64
65 return;
66 }
67
68 /*ARGSUSED*/
69 int
70 rumpuser_thread_create(void *(*f)(void *), void *arg, const char *thrname,
71 int joinable, int pri, int cpuidx, void **tptr)
72 {
73
74 fprintf(stderr, "rumpuser: threads not available\n");
75 abort();
76 return 0;
77 }
78
79 void
80 rumpuser_thread_exit(void)
81 {
82
83 fprintf(stderr, "rumpuser: threads not available\n");
84 abort();
85 }
86
87 int
88 rumpuser_thread_join(void *p)
89 {
90
91 return 0;
92 }
93
94 void
95 rumpuser_mutex_init(struct rumpuser_mtx **mtx, int flgas)
96 {
97
98 *mtx = calloc(1, sizeof(struct rumpuser_mtx));
99 }
100
101 void
102 rumpuser_mutex_enter(struct rumpuser_mtx *mtx)
103 {
104
105 mtx->v++;
106 mtx->o = curlwp;
107 }
108
109 void
110 rumpuser_mutex_enter_nowrap(struct rumpuser_mtx *mtx)
111 {
112
113 rumpuser_mutex_enter(mtx);
114 }
115
116 int
117 rumpuser_mutex_tryenter(struct rumpuser_mtx *mtx)
118 {
119
120 mtx->v++;
121 return 0;
122 }
123
124 void
125 rumpuser_mutex_exit(struct rumpuser_mtx *mtx)
126 {
127
128 assert(mtx->v > 0);
129 if (--mtx->v == 0)
130 mtx->o = NULL;
131 }
132
133 void
134 rumpuser_mutex_destroy(struct rumpuser_mtx *mtx)
135 {
136
137 free(mtx);
138 }
139
140 void
141 rumpuser_mutex_owner(struct rumpuser_mtx *mtx, struct lwp **lp)
142 {
143
144 *lp = mtx->o;
145 }
146
147 void
148 rumpuser_rw_init(struct rumpuser_rw **rw)
149 {
150
151 *rw = calloc(1, sizeof(struct rumpuser_rw));
152 }
153
154 void
155 rumpuser_rw_enter(struct rumpuser_rw *rw, int write)
156 {
157
158 if (write) {
159 rw->v++;
160 assert(rw->v == 1);
161 } else {
162 assert(rw->v <= 0);
163 rw->v--;
164 }
165 }
166
167 int
168 rumpuser_rw_tryenter(struct rumpuser_rw *rw, int write)
169 {
170
171 rumpuser_rw_enter(rw, write);
172 return 0;
173 }
174
175 void
176 rumpuser_rw_exit(struct rumpuser_rw *rw)
177 {
178
179 if (rw->v > 0) {
180 assert(rw->v == 1);
181 rw->v--;
182 } else {
183 rw->v++;
184 }
185 }
186
187 void
188 rumpuser_rw_destroy(struct rumpuser_rw *rw)
189 {
190
191 free(rw);
192 }
193
194 void
195 rumpuser_rw_held(struct rumpuser_rw *rw, int *rvp)
196 {
197
198 *rvp = rw->v != 0;
199 }
200
201 void
202 rumpuser_rw_rdheld(struct rumpuser_rw *rw, int *rvp)
203 {
204
205 *rvp = rw->v < 0;
206 }
207
208 void
209 rumpuser_rw_wrheld(struct rumpuser_rw *rw, int *rvp)
210 {
211
212 *rvp = rw->v > 0;
213 }
214
215 /*ARGSUSED*/
216 void
217 rumpuser_cv_init(struct rumpuser_cv **cv)
218 {
219
220 }
221
222 /*ARGSUSED*/
223 void
224 rumpuser_cv_destroy(struct rumpuser_cv *cv)
225 {
226
227 }
228
229 /*ARGSUSED*/
230 void
231 rumpuser_cv_wait(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx)
232 {
233
234 }
235
236 /*ARGSUSED*/
237 void
238 rumpuser_cv_wait_nowrap(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx)
239 {
240
241 }
242
243 /*ARGSUSED*/
244 int
245 rumpuser_cv_timedwait(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx,
246 int64_t sec, int64_t nsec)
247 {
248 struct timespec ts;
249
250 /*LINTED*/
251 ts.tv_sec = sec;
252 /*LINTED*/
253 ts.tv_nsec = nsec;
254
255 nanosleep(&ts, NULL);
256 return 0;
257 }
258
259 /*ARGSUSED*/
260 void
261 rumpuser_cv_signal(struct rumpuser_cv *cv)
262 {
263
264 }
265
266 /*ARGSUSED*/
267 void
268 rumpuser_cv_broadcast(struct rumpuser_cv *cv)
269 {
270
271 }
272
273 /*ARGSUSED*/
274 void
275 rumpuser_cv_has_waiters(struct rumpuser_cv *cv, int *rvp)
276 {
277
278 *rvp = 0;
279 }
280
281 /*
282 * curlwp
283 */
284
285 void
286 rumpuser_curlwpop(enum rumplwpop op, struct lwp *l)
287 {
288
289 switch (op) {
290 case RUMPUSER_LWP_CREATE:
291 case RUMPUSER_LWP_DESTROY:
292 break;
293 case RUMPUSER_LWP_SET:
294 curlwp = l;
295 break;
296 }
297 }
298
299 struct lwp *
300 rumpuser_curlwp(void)
301 {
302
303 return curlwp;
304 }
305