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