1/*	$NetBSD: rumpuser_pth_dummy.c,v 1.1 2010/02/26 18:54:20 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 <sys/cdefs.h>
29#if !defined(lint)
30__RCSID("$NetBSD: rumpuser_pth_dummy.c,v 1.1 2010/02/26 18:54:20 pooka Exp $");
31#endif /* !lint */
32
33#include <sys/time.h>
34
35#include <assert.h>
36#include <errno.h>
37#include <stdlib.h>
38#include <stdio.h>
39#include <string.h>
40#include <stdint.h>
41
42#include <rump/rumpuser.h>
43
44#include "rumpuser_int.h"
45
46struct rumpuser_cv {};
47
48struct rumpuser_mtx {
49	int v;
50};
51
52struct rumpuser_rw {
53	int v;
54};
55
56struct rumpuser_mtx rumpuser_aio_mtx;
57struct rumpuser_cv rumpuser_aio_cv;
58int rumpuser_aio_head, rumpuser_aio_tail;
59struct rumpuser_aio rumpuser_aios[N_AIOS];
60
61void donada(int);
62/*ARGSUSED*/
63void donada(int arg) {}
64void dounnada(int, int *);
65/*ARGSUSED*/
66void dounnada(int arg, int *ap) {}
67kernel_lockfn   rumpuser__klock = donada;
68kernel_unlockfn rumpuser__kunlock = dounnada;
69
70/*ARGSUSED*/
71void
72rumpuser_thrinit(kernel_lockfn lockfn, kernel_unlockfn unlockfn, int threads)
73{
74
75}
76
77/*ARGSUSED*/
78void
79rumpuser_biothread(void *arg)
80{
81
82	fprintf(stderr, "rumpuser: threads not available\n");
83	abort();
84}
85
86/*ARGSUSED*/
87int
88rumpuser_thread_create(void *(*f)(void *), void *arg, const char *thrname)
89{
90
91	fprintf(stderr, "rumpuser: threads not available\n");
92	abort();
93	return 0;
94}
95
96void
97rumpuser_thread_exit(void)
98{
99
100	fprintf(stderr, "rumpuser: threads not available\n");
101	abort();
102}
103
104void
105rumpuser_mutex_init(struct rumpuser_mtx **mtx)
106{
107
108	*mtx = calloc(1, sizeof(struct rumpuser_mtx));
109}
110
111void
112rumpuser_mutex_recursive_init(struct rumpuser_mtx **mtx)
113{
114
115	rumpuser_mutex_init(mtx);
116}
117
118void
119rumpuser_mutex_enter(struct rumpuser_mtx *mtx)
120{
121
122	mtx->v++;
123}
124
125int
126rumpuser_mutex_tryenter(struct rumpuser_mtx *mtx)
127{
128
129	mtx->v++;
130	return 1;
131}
132
133void
134rumpuser_mutex_exit(struct rumpuser_mtx *mtx)
135{
136
137	mtx->v--;
138}
139
140void
141rumpuser_mutex_destroy(struct rumpuser_mtx *mtx)
142{
143
144	free(mtx);
145}
146
147int
148rumpuser_mutex_held(struct rumpuser_mtx *mtx)
149{
150
151	return mtx->v;
152}
153
154void
155rumpuser_rw_init(struct rumpuser_rw **rw)
156{
157
158	*rw = calloc(1, sizeof(struct rumpuser_rw));
159}
160
161void
162rumpuser_rw_enter(struct rumpuser_rw *rw, int write)
163{
164
165	if (write) {
166		rw->v++;
167		assert(rw->v == 1);
168	} else {
169		assert(rw->v <= 0);
170		rw->v--;
171	}
172}
173
174int
175rumpuser_rw_tryenter(struct rumpuser_rw *rw, int write)
176{
177
178	rumpuser_rw_enter(rw, write);
179	return 1;
180}
181
182void
183rumpuser_rw_exit(struct rumpuser_rw *rw)
184{
185
186	if (rw->v > 0) {
187		assert(rw->v == 1);
188		rw->v--;
189	} else {
190		rw->v++;
191	}
192}
193
194void
195rumpuser_rw_destroy(struct rumpuser_rw *rw)
196{
197
198	free(rw);
199}
200
201int
202rumpuser_rw_held(struct rumpuser_rw *rw)
203{
204
205	return rw->v != 0;
206}
207
208int
209rumpuser_rw_rdheld(struct rumpuser_rw *rw)
210{
211
212	return rw->v < 0;
213}
214
215int
216rumpuser_rw_wrheld(struct rumpuser_rw *rw)
217{
218
219	return rw->v > 0;
220}
221
222/*ARGSUSED*/
223void
224rumpuser_cv_init(struct rumpuser_cv **cv)
225{
226
227}
228
229/*ARGSUSED*/
230void
231rumpuser_cv_destroy(struct rumpuser_cv *cv)
232{
233
234}
235
236/*ARGSUSED*/
237void
238rumpuser_cv_wait(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx)
239{
240
241}
242
243/*ARGSUSED*/
244int
245rumpuser_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*/
260void
261rumpuser_cv_signal(struct rumpuser_cv *cv)
262{
263
264}
265
266/*ARGSUSED*/
267void
268rumpuser_cv_broadcast(struct rumpuser_cv *cv)
269{
270
271}
272
273/*ARGSUSED*/
274int
275rumpuser_cv_has_waiters(struct rumpuser_cv *cv)
276{
277
278	return 0;
279}
280
281/*
282 * curlwp
283 */
284
285static struct lwp *curlwp;
286void
287rumpuser_set_curlwp(struct lwp *l)
288{
289
290	curlwp = l;
291}
292
293struct lwp *
294rumpuser_get_curlwp(void)
295{
296
297	return curlwp;
298}
299