Home | History | Annotate | Line # | Download | only in librumpuser
rumpuser_pth_dummy.c revision 1.14
      1 /*	$NetBSD: rumpuser_pth_dummy.c,v 1.14 2013/05/07 15:37:05 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.14 2013/05/07 15:37:05 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 #include <time.h>
     44 
     45 #include <rump/rumpuser.h>
     46 
     47 #include "rumpuser_int.h"
     48 
     49 static struct lwp *curlwp;
     50 
     51 struct rumpuser_cv {};
     52 
     53 struct rumpuser_mtx {
     54 	int v;
     55 	struct lwp *o;
     56 };
     57 
     58 struct rumpuser_rw {
     59 	int v;
     60 };
     61 
     62 void
     63 rumpuser__thrinit(void)
     64 {
     65 
     66 	return;
     67 }
     68 
     69 /*ARGSUSED*/
     70 int
     71 rumpuser_thread_create(void *(*f)(void *), void *arg, const char *thrname,
     72 	int joinable, int pri, int cpuidx, void **tptr)
     73 {
     74 
     75 	fprintf(stderr, "rumpuser: threads not available\n");
     76 	abort();
     77 	return 0;
     78 }
     79 
     80 void
     81 rumpuser_thread_exit(void)
     82 {
     83 
     84 	fprintf(stderr, "rumpuser: threads not available\n");
     85 	abort();
     86 }
     87 
     88 int
     89 rumpuser_thread_join(void *p)
     90 {
     91 
     92 	return 0;
     93 }
     94 
     95 void
     96 rumpuser_mutex_init(struct rumpuser_mtx **mtx, int flgas)
     97 {
     98 
     99 	*mtx = calloc(1, sizeof(struct rumpuser_mtx));
    100 }
    101 
    102 void
    103 rumpuser_mutex_enter(struct rumpuser_mtx *mtx)
    104 {
    105 
    106 	mtx->v++;
    107 	mtx->o = curlwp;
    108 }
    109 
    110 void
    111 rumpuser_mutex_enter_nowrap(struct rumpuser_mtx *mtx)
    112 {
    113 
    114 	rumpuser_mutex_enter(mtx);
    115 }
    116 
    117 int
    118 rumpuser_mutex_tryenter(struct rumpuser_mtx *mtx)
    119 {
    120 
    121 	mtx->v++;
    122 	return 0;
    123 }
    124 
    125 void
    126 rumpuser_mutex_exit(struct rumpuser_mtx *mtx)
    127 {
    128 
    129 	assert(mtx->v > 0);
    130 	if (--mtx->v == 0)
    131 		mtx->o = NULL;
    132 }
    133 
    134 void
    135 rumpuser_mutex_destroy(struct rumpuser_mtx *mtx)
    136 {
    137 
    138 	free(mtx);
    139 }
    140 
    141 void
    142 rumpuser_mutex_owner(struct rumpuser_mtx *mtx, struct lwp **lp)
    143 {
    144 
    145 	*lp = mtx->o;
    146 }
    147 
    148 void
    149 rumpuser_rw_init(struct rumpuser_rw **rw)
    150 {
    151 
    152 	*rw = calloc(1, sizeof(struct rumpuser_rw));
    153 }
    154 
    155 void
    156 rumpuser_rw_enter(struct rumpuser_rw *rw, enum rumprwlock lk)
    157 {
    158 
    159 	switch (lk) {
    160 	case RUMPUSER_RW_WRITER:
    161 		rw->v++;
    162 		assert(rw->v == 1);
    163 		break;
    164 	case RUMPUSER_RW_READER:
    165 		assert(rw->v <= 0);
    166 		rw->v--;
    167 		break;
    168 	}
    169 }
    170 
    171 int
    172 rumpuser_rw_tryenter(struct rumpuser_rw *rw, enum rumprwlock lk)
    173 {
    174 
    175 	rumpuser_rw_enter(rw, lk);
    176 	return 0;
    177 }
    178 
    179 void
    180 rumpuser_rw_exit(struct rumpuser_rw *rw)
    181 {
    182 
    183 	if (rw->v > 0) {
    184 		assert(rw->v == 1);
    185 		rw->v--;
    186 	} else {
    187 		rw->v++;
    188 	}
    189 }
    190 
    191 void
    192 rumpuser_rw_destroy(struct rumpuser_rw *rw)
    193 {
    194 
    195 	free(rw);
    196 }
    197 
    198 void
    199 rumpuser_rw_held(struct rumpuser_rw *rw, enum rumprwlock lk, int *rvp)
    200 {
    201 
    202 	switch (lk) {
    203 	case RUMPUSER_RW_WRITER:
    204 		*rvp = rw->v > 0;
    205 		break;
    206 	case RUMPUSER_RW_READER:
    207 		*rvp = rw->v < 0;
    208 		break;
    209 	}
    210 }
    211 
    212 /*ARGSUSED*/
    213 void
    214 rumpuser_cv_init(struct rumpuser_cv **cv)
    215 {
    216 
    217 }
    218 
    219 /*ARGSUSED*/
    220 void
    221 rumpuser_cv_destroy(struct rumpuser_cv *cv)
    222 {
    223 
    224 }
    225 
    226 /*ARGSUSED*/
    227 void
    228 rumpuser_cv_wait(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx)
    229 {
    230 
    231 }
    232 
    233 /*ARGSUSED*/
    234 void
    235 rumpuser_cv_wait_nowrap(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx)
    236 {
    237 
    238 }
    239 
    240 /*ARGSUSED*/
    241 int
    242 rumpuser_cv_timedwait(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx,
    243 	int64_t sec, int64_t nsec)
    244 {
    245 	struct timespec ts;
    246 
    247 	/*LINTED*/
    248 	ts.tv_sec = sec;
    249 	/*LINTED*/
    250 	ts.tv_nsec = nsec;
    251 
    252 	nanosleep(&ts, NULL);
    253 	return 0;
    254 }
    255 
    256 /*ARGSUSED*/
    257 void
    258 rumpuser_cv_signal(struct rumpuser_cv *cv)
    259 {
    260 
    261 }
    262 
    263 /*ARGSUSED*/
    264 void
    265 rumpuser_cv_broadcast(struct rumpuser_cv *cv)
    266 {
    267 
    268 }
    269 
    270 /*ARGSUSED*/
    271 void
    272 rumpuser_cv_has_waiters(struct rumpuser_cv *cv, int *rvp)
    273 {
    274 
    275 	*rvp = 0;
    276 }
    277 
    278 /*
    279  * curlwp
    280  */
    281 
    282 void
    283 rumpuser_curlwpop(enum rumplwpop op, struct lwp *l)
    284 {
    285 
    286 	switch (op) {
    287 	case RUMPUSER_LWP_CREATE:
    288 	case RUMPUSER_LWP_DESTROY:
    289 		break;
    290 	case RUMPUSER_LWP_SET:
    291 		curlwp = l;
    292 		break;
    293 	}
    294 }
    295 
    296 struct lwp *
    297 rumpuser_curlwp(void)
    298 {
    299 
    300 	return curlwp;
    301 }
    302