2014-06-17 10:43:21 +04:00
|
|
|
/* $NetBSD: rumpuser_pth_dummy.c,v 1.17 2014/06/17 06:43:21 alnsn Exp $ */
|
2009-01-21 00:43:13 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2012-11-02 15:11:27 +04:00
|
|
|
#include "rumpuser_port.h"
|
|
|
|
|
2009-01-21 00:43:13 +03:00
|
|
|
#if !defined(lint)
|
2014-06-17 10:43:21 +04:00
|
|
|
__RCSID("$NetBSD: rumpuser_pth_dummy.c,v 1.17 2014/06/17 06:43:21 alnsn Exp $");
|
2009-01-21 00:43:13 +03:00
|
|
|
#endif /* !lint */
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
2013-05-07 19:37:05 +04:00
|
|
|
#include <time.h>
|
2009-01-21 00:43:13 +03:00
|
|
|
|
|
|
|
#include <rump/rumpuser.h>
|
|
|
|
|
|
|
|
#include "rumpuser_int.h"
|
|
|
|
|
2012-11-02 20:55:02 +04:00
|
|
|
static struct lwp *curlwp;
|
|
|
|
|
2009-01-21 00:43:13 +03:00
|
|
|
struct rumpuser_cv {};
|
|
|
|
|
|
|
|
struct rumpuser_mtx {
|
|
|
|
int v;
|
2012-11-02 20:55:02 +04:00
|
|
|
struct lwp *o;
|
2009-01-21 00:43:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct rumpuser_rw {
|
|
|
|
int v;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2013-04-27 18:59:08 +04:00
|
|
|
rumpuser__thrinit(void)
|
2009-01-21 00:43:13 +03:00
|
|
|
{
|
|
|
|
|
2013-04-27 18:59:08 +04:00
|
|
|
return;
|
2009-01-21 00:43:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
2012-11-02 15:11:27 +04:00
|
|
|
rumpuser_thread_create(void *(*f)(void *), void *arg, const char *thrname,
|
2013-04-30 17:29:28 +04:00
|
|
|
int joinable, int pri, int cpuidx, void **tptr)
|
2009-01-21 00:43:13 +03:00
|
|
|
{
|
|
|
|
|
2009-01-22 19:05:34 +03:00
|
|
|
fprintf(stderr, "rumpuser: threads not available\n");
|
2009-01-21 00:43:13 +03:00
|
|
|
abort();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-18 13:22:21 +03:00
|
|
|
rumpuser_thread_exit(void)
|
2009-01-21 00:43:13 +03:00
|
|
|
{
|
|
|
|
|
2011-05-24 00:49:08 +04:00
|
|
|
fprintf(stderr, "rumpuser: threads not available\n");
|
|
|
|
abort();
|
2009-01-21 00:43:13 +03:00
|
|
|
}
|
|
|
|
|
2013-04-30 17:37:03 +04:00
|
|
|
int
|
|
|
|
rumpuser_thread_join(void *p)
|
|
|
|
{
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-21 00:43:13 +03:00
|
|
|
void
|
2013-04-27 20:32:56 +04:00
|
|
|
rumpuser_mutex_init(struct rumpuser_mtx **mtx, int flgas)
|
2012-11-02 17:31:26 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
*mtx = calloc(1, sizeof(struct rumpuser_mtx));
|
|
|
|
}
|
|
|
|
|
2009-01-21 00:43:13 +03:00
|
|
|
void
|
|
|
|
rumpuser_mutex_enter(struct rumpuser_mtx *mtx)
|
|
|
|
{
|
|
|
|
|
|
|
|
mtx->v++;
|
2012-11-02 20:55:02 +04:00
|
|
|
mtx->o = curlwp;
|
2009-01-21 00:43:13 +03:00
|
|
|
}
|
|
|
|
|
2012-11-06 22:31:14 +04:00
|
|
|
void
|
|
|
|
rumpuser_mutex_enter_nowrap(struct rumpuser_mtx *mtx)
|
|
|
|
{
|
|
|
|
|
|
|
|
rumpuser_mutex_enter(mtx);
|
|
|
|
}
|
|
|
|
|
2009-01-21 00:43:13 +03:00
|
|
|
int
|
|
|
|
rumpuser_mutex_tryenter(struct rumpuser_mtx *mtx)
|
|
|
|
{
|
|
|
|
|
|
|
|
mtx->v++;
|
2013-04-30 17:37:03 +04:00
|
|
|
return 0;
|
2009-01-21 00:43:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rumpuser_mutex_exit(struct rumpuser_mtx *mtx)
|
|
|
|
{
|
|
|
|
|
2012-11-02 20:55:02 +04:00
|
|
|
assert(mtx->v > 0);
|
|
|
|
if (--mtx->v == 0)
|
|
|
|
mtx->o = NULL;
|
2009-01-21 00:43:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rumpuser_mutex_destroy(struct rumpuser_mtx *mtx)
|
|
|
|
{
|
|
|
|
|
|
|
|
free(mtx);
|
|
|
|
}
|
|
|
|
|
2013-04-30 17:37:03 +04:00
|
|
|
void
|
|
|
|
rumpuser_mutex_owner(struct rumpuser_mtx *mtx, struct lwp **lp)
|
2012-11-02 20:55:02 +04:00
|
|
|
{
|
|
|
|
|
2013-04-30 17:37:03 +04:00
|
|
|
*lp = mtx->o;
|
2012-11-02 20:55:02 +04:00
|
|
|
}
|
|
|
|
|
2009-01-21 00:43:13 +03:00
|
|
|
void
|
|
|
|
rumpuser_rw_init(struct rumpuser_rw **rw)
|
|
|
|
{
|
|
|
|
|
|
|
|
*rw = calloc(1, sizeof(struct rumpuser_rw));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-15 18:52:49 +04:00
|
|
|
rumpuser_rw_enter(int enum_rumprwlock, struct rumpuser_rw *rw)
|
2009-01-21 00:43:13 +03:00
|
|
|
{
|
2013-05-15 18:52:49 +04:00
|
|
|
enum rumprwlock lk = enum_rumprwlock;
|
2009-01-21 00:43:13 +03:00
|
|
|
|
2013-05-07 19:37:05 +04:00
|
|
|
switch (lk) {
|
|
|
|
case RUMPUSER_RW_WRITER:
|
2009-01-21 00:43:13 +03:00
|
|
|
rw->v++;
|
2009-04-29 18:58:50 +04:00
|
|
|
assert(rw->v == 1);
|
2013-05-07 19:37:05 +04:00
|
|
|
break;
|
|
|
|
case RUMPUSER_RW_READER:
|
2009-01-21 00:43:13 +03:00
|
|
|
assert(rw->v <= 0);
|
|
|
|
rw->v--;
|
2013-05-07 19:37:05 +04:00
|
|
|
break;
|
2009-01-21 00:43:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-05-15 18:52:49 +04:00
|
|
|
rumpuser_rw_tryenter(int enum_rumprwlock, struct rumpuser_rw *rw)
|
2009-01-21 00:43:13 +03:00
|
|
|
{
|
|
|
|
|
2013-05-15 18:52:49 +04:00
|
|
|
rumpuser_rw_enter(enum_rumprwlock, rw);
|
2013-04-30 17:37:03 +04:00
|
|
|
return 0;
|
2009-01-21 00:43:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rumpuser_rw_exit(struct rumpuser_rw *rw)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (rw->v > 0) {
|
|
|
|
assert(rw->v == 1);
|
|
|
|
rw->v--;
|
|
|
|
} else {
|
|
|
|
rw->v++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rumpuser_rw_destroy(struct rumpuser_rw *rw)
|
|
|
|
{
|
|
|
|
|
|
|
|
free(rw);
|
|
|
|
}
|
|
|
|
|
2013-04-30 17:37:03 +04:00
|
|
|
void
|
2013-05-15 18:52:49 +04:00
|
|
|
rumpuser_rw_held(int enum_rumprwlock, struct rumpuser_rw *rw, int *rvp)
|
2009-01-21 00:43:13 +03:00
|
|
|
{
|
2013-05-15 18:52:49 +04:00
|
|
|
enum rumprwlock lk = enum_rumprwlock;
|
2009-01-21 00:43:13 +03:00
|
|
|
|
2013-05-07 19:37:05 +04:00
|
|
|
switch (lk) {
|
|
|
|
case RUMPUSER_RW_WRITER:
|
|
|
|
*rvp = rw->v > 0;
|
|
|
|
break;
|
|
|
|
case RUMPUSER_RW_READER:
|
|
|
|
*rvp = rw->v < 0;
|
|
|
|
break;
|
|
|
|
}
|
2009-01-21 00:43:13 +03:00
|
|
|
}
|
|
|
|
|
2013-05-07 20:40:31 +04:00
|
|
|
void
|
|
|
|
rumpuser_rw_downgrade(struct rumpuser_rw *rw)
|
|
|
|
{
|
|
|
|
|
|
|
|
assert(rw->v == 1);
|
|
|
|
rw->v = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rumpuser_rw_tryupgrade(struct rumpuser_rw *rw)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (rw->v == -1) {
|
|
|
|
rw->v = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EBUSY;
|
|
|
|
}
|
|
|
|
|
2009-01-21 00:43:13 +03:00
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
rumpuser_cv_init(struct rumpuser_cv **cv)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
rumpuser_cv_destroy(struct rumpuser_cv *cv)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2009-12-08 11:18:24 +03:00
|
|
|
|
2009-01-21 00:43:13 +03:00
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
rumpuser_cv_wait(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-30 17:37:03 +04:00
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
rumpuser_cv_wait_nowrap(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-21 00:43:13 +03:00
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
|
|
|
rumpuser_cv_timedwait(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx,
|
2009-11-19 17:44:58 +03:00
|
|
|
int64_t sec, int64_t nsec)
|
2009-01-21 00:43:13 +03:00
|
|
|
{
|
2009-11-19 17:44:58 +03:00
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
/*LINTED*/
|
|
|
|
ts.tv_sec = sec;
|
|
|
|
/*LINTED*/
|
|
|
|
ts.tv_nsec = nsec;
|
2009-01-21 00:43:13 +03:00
|
|
|
|
2009-11-19 17:44:58 +03:00
|
|
|
nanosleep(&ts, NULL);
|
2009-01-21 00:43:13 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
rumpuser_cv_signal(struct rumpuser_cv *cv)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
rumpuser_cv_broadcast(struct rumpuser_cv *cv)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
2013-04-30 17:37:03 +04:00
|
|
|
void
|
|
|
|
rumpuser_cv_has_waiters(struct rumpuser_cv *cv, int *rvp)
|
2009-01-21 00:43:13 +03:00
|
|
|
{
|
|
|
|
|
2013-04-30 17:37:03 +04:00
|
|
|
*rvp = 0;
|
2009-01-21 00:43:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* curlwp
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2013-05-15 18:52:49 +04:00
|
|
|
rumpuser_curlwpop(int enum_rumplwpop, struct lwp *l)
|
2009-01-21 00:43:13 +03:00
|
|
|
{
|
2013-05-15 18:52:49 +04:00
|
|
|
enum rumplwpop op = enum_rumplwpop;
|
2009-01-21 00:43:13 +03:00
|
|
|
|
2013-05-02 23:14:59 +04:00
|
|
|
switch (op) {
|
|
|
|
case RUMPUSER_LWP_CREATE:
|
|
|
|
case RUMPUSER_LWP_DESTROY:
|
|
|
|
break;
|
|
|
|
case RUMPUSER_LWP_SET:
|
|
|
|
curlwp = l;
|
|
|
|
break;
|
2013-05-15 18:52:49 +04:00
|
|
|
case RUMPUSER_LWP_CLEAR:
|
|
|
|
assert(curlwp == l);
|
|
|
|
curlwp = NULL;
|
|
|
|
break;
|
2013-05-02 23:14:59 +04:00
|
|
|
}
|
2009-01-21 00:43:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct lwp *
|
2013-05-02 23:14:59 +04:00
|
|
|
rumpuser_curlwp(void)
|
2009-01-21 00:43:13 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
return curlwp;
|
|
|
|
}
|