rumpuser_pth_dummy.c revision 1.3 1 /* $NetBSD: rumpuser_pth_dummy.c,v 1.3 2012/11/02 11:11:27 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.3 2012/11/02 11:11:27 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 struct rumpuser_cv {};
49
50 struct rumpuser_mtx {
51 int v;
52 };
53
54 struct rumpuser_rw {
55 int v;
56 };
57
58 struct rumpuser_mtx rumpuser_aio_mtx;
59 struct rumpuser_cv rumpuser_aio_cv;
60 int rumpuser_aio_head, rumpuser_aio_tail;
61 struct rumpuser_aio rumpuser_aios[N_AIOS];
62
63 /*ARGSUSED*/
64 void
65 rumpuser_thrinit(kernel_lockfn lockfn, kernel_unlockfn unlockfn, int threads)
66 {
67
68 rumpuser__klock = lockfn;
69 rumpuser__kunlock = unlockfn;
70 }
71
72 /*ARGSUSED*/
73 void
74 rumpuser_biothread(void *arg)
75 {
76
77 fprintf(stderr, "rumpuser: threads not available\n");
78 abort();
79 }
80
81 /*ARGSUSED*/
82 int
83 rumpuser_thread_create(void *(*f)(void *), void *arg, const char *thrname,
84 int joinable, void **tptr)
85 {
86
87 fprintf(stderr, "rumpuser: threads not available\n");
88 abort();
89 return 0;
90 }
91
92 void
93 rumpuser_thread_exit(void)
94 {
95
96 fprintf(stderr, "rumpuser: threads not available\n");
97 abort();
98 }
99
100 void
101 rumpuser_mutex_init(struct rumpuser_mtx **mtx)
102 {
103
104 *mtx = calloc(1, sizeof(struct rumpuser_mtx));
105 }
106
107 void
108 rumpuser_mutex_enter(struct rumpuser_mtx *mtx)
109 {
110
111 mtx->v++;
112 }
113
114 int
115 rumpuser_mutex_tryenter(struct rumpuser_mtx *mtx)
116 {
117
118 mtx->v++;
119 return 1;
120 }
121
122 void
123 rumpuser_mutex_exit(struct rumpuser_mtx *mtx)
124 {
125
126 mtx->v--;
127 }
128
129 void
130 rumpuser_mutex_destroy(struct rumpuser_mtx *mtx)
131 {
132
133 free(mtx);
134 }
135
136 void
137 rumpuser_rw_init(struct rumpuser_rw **rw)
138 {
139
140 *rw = calloc(1, sizeof(struct rumpuser_rw));
141 }
142
143 void
144 rumpuser_rw_enter(struct rumpuser_rw *rw, int write)
145 {
146
147 if (write) {
148 rw->v++;
149 assert(rw->v == 1);
150 } else {
151 assert(rw->v <= 0);
152 rw->v--;
153 }
154 }
155
156 int
157 rumpuser_rw_tryenter(struct rumpuser_rw *rw, int write)
158 {
159
160 rumpuser_rw_enter(rw, write);
161 return 1;
162 }
163
164 void
165 rumpuser_rw_exit(struct rumpuser_rw *rw)
166 {
167
168 if (rw->v > 0) {
169 assert(rw->v == 1);
170 rw->v--;
171 } else {
172 rw->v++;
173 }
174 }
175
176 void
177 rumpuser_rw_destroy(struct rumpuser_rw *rw)
178 {
179
180 free(rw);
181 }
182
183 int
184 rumpuser_rw_held(struct rumpuser_rw *rw)
185 {
186
187 return rw->v != 0;
188 }
189
190 int
191 rumpuser_rw_rdheld(struct rumpuser_rw *rw)
192 {
193
194 return rw->v < 0;
195 }
196
197 int
198 rumpuser_rw_wrheld(struct rumpuser_rw *rw)
199 {
200
201 return rw->v > 0;
202 }
203
204 /*ARGSUSED*/
205 void
206 rumpuser_cv_init(struct rumpuser_cv **cv)
207 {
208
209 }
210
211 /*ARGSUSED*/
212 void
213 rumpuser_cv_destroy(struct rumpuser_cv *cv)
214 {
215
216 }
217
218 /*ARGSUSED*/
219 void
220 rumpuser_cv_wait(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx)
221 {
222
223 }
224
225 /*ARGSUSED*/
226 int
227 rumpuser_cv_timedwait(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx,
228 int64_t sec, int64_t nsec)
229 {
230 struct timespec ts;
231
232 /*LINTED*/
233 ts.tv_sec = sec;
234 /*LINTED*/
235 ts.tv_nsec = nsec;
236
237 nanosleep(&ts, NULL);
238 return 0;
239 }
240
241 /*ARGSUSED*/
242 void
243 rumpuser_cv_signal(struct rumpuser_cv *cv)
244 {
245
246 }
247
248 /*ARGSUSED*/
249 void
250 rumpuser_cv_broadcast(struct rumpuser_cv *cv)
251 {
252
253 }
254
255 /*ARGSUSED*/
256 int
257 rumpuser_cv_has_waiters(struct rumpuser_cv *cv)
258 {
259
260 return 0;
261 }
262
263 /*
264 * curlwp
265 */
266
267 static struct lwp *curlwp;
268 void
269 rumpuser_set_curlwp(struct lwp *l)
270 {
271
272 curlwp = l;
273 }
274
275 struct lwp *
276 rumpuser_get_curlwp(void)
277 {
278
279 return curlwp;
280 }
281