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