Home | History | Annotate | Line # | Download | only in rumpkern
locks.c revision 1.1.2.2
      1 /*	$NetBSD: locks.c,v 1.1.2.2 2007/10/31 23:14:16 joerg Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
      5  *
      6  * Development of this software was supported by the
      7  * Finnish Cultural Foundation.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     19  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     21  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  */
     30 
     31 #include <sys/param.h>
     32 #include <sys/mutex.h>
     33 #include <sys/rwlock.h>
     34 
     35 #include "rumpuser.h"
     36 
     37 void
     38 mutex_init(kmutex_t *mtx, kmutex_type_t type, int ipl)
     39 {
     40 
     41 	rumpuser_mutex_init(&mtx->kmtx_mtx);
     42 }
     43 
     44 void
     45 mutex_destroy(kmutex_t *mtx)
     46 {
     47 
     48 	rumpuser_mutex_destroy(mtx->kmtx_mtx);
     49 }
     50 
     51 void
     52 mutex_enter(kmutex_t *mtx)
     53 {
     54 
     55 	rumpuser_mutex_enter(mtx->kmtx_mtx);
     56 }
     57 
     58 int
     59 mutex_tryenter(kmutex_t *mtx)
     60 {
     61 	int rv;
     62 
     63 	rv = rumpuser_mutex_tryenter(mtx->kmtx_mtx);
     64 	if (rv)
     65 		return 0;
     66 	else
     67 		return 1;
     68 }
     69 
     70 void
     71 mutex_exit(kmutex_t *mtx)
     72 {
     73 
     74 	rumpuser_mutex_exit(mtx->kmtx_mtx);
     75 }
     76 
     77 int
     78 mutex_owned(kmutex_t *mtx)
     79 {
     80 
     81 	/* XXX */
     82 	return 1;
     83 }
     84 
     85 /* reader/writer locks */
     86 
     87 void
     88 rw_init(krwlock_t *rw)
     89 {
     90 
     91 	rumpuser_rw_init(&rw->krw_pthlock);
     92 }
     93 
     94 void
     95 rw_destroy(krwlock_t *rw)
     96 {
     97 
     98 	rumpuser_rw_destroy(rw->krw_pthlock);
     99 }
    100 
    101 void
    102 rw_enter(krwlock_t *rw, const krw_t op)
    103 {
    104 
    105 	rumpuser_rw_enter(rw->krw_pthlock, op == RW_WRITER);
    106 }
    107 
    108 int
    109 rw_tryenter(krwlock_t *rw, const krw_t op)
    110 {
    111 
    112 	return rumpuser_rw_tryenter(rw->krw_pthlock, op == RW_WRITER);
    113 }
    114 
    115 void
    116 rw_exit(krwlock_t *rw)
    117 {
    118 
    119 	rumpuser_rw_exit(rw->krw_pthlock);
    120 }
    121 
    122 /* always fails */
    123 int
    124 rw_tryupgrade(krwlock_t *rw)
    125 {
    126 
    127 	return 0;
    128 }
    129 
    130 /* curriculum vitaes */
    131 
    132 /* forgive me for I have sinned */
    133 #define RUMPCV(a) ((struct rumpuser_cv *)(__UNCONST((a)->cv_wmesg)))
    134 
    135 void
    136 cv_init(kcondvar_t *cv, const char *msg)
    137 {
    138 
    139 	rumpuser_cv_init((struct rumpuser_cv **)__UNCONST(&cv->cv_wmesg));
    140 }
    141 
    142 void
    143 cv_destroy(kcondvar_t *cv)
    144 {
    145 
    146 	rumpuser_cv_destroy(RUMPCV(cv));
    147 }
    148 
    149 void
    150 cv_wait(kcondvar_t *cv, kmutex_t *mtx)
    151 {
    152 
    153 	rumpuser_cv_wait(RUMPCV(cv), mtx->kmtx_mtx);
    154 }
    155 
    156 void
    157 cv_signal(kcondvar_t *cv)
    158 {
    159 
    160 	rumpuser_cv_signal(RUMPCV(cv));
    161 }
    162