Module Name: src
Committed By: pooka
Date: Wed Nov 11 16:47:50 UTC 2009
Modified Files:
src/sys/rump/librump/rumpkern: ltsleep.c
Log Message:
support timeouts in tsleep
To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/rump/librump/rumpkern/ltsleep.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/rump/librump/rumpkern/ltsleep.c
diff -u src/sys/rump/librump/rumpkern/ltsleep.c:1.19 src/sys/rump/librump/rumpkern/ltsleep.c:1.20
--- src/sys/rump/librump/rumpkern/ltsleep.c:1.19 Thu Oct 15 00:28:46 2009
+++ src/sys/rump/librump/rumpkern/ltsleep.c Wed Nov 11 16:47:50 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: ltsleep.c,v 1.19 2009/10/15 00:28:46 pooka Exp $ */
+/* $NetBSD: ltsleep.c,v 1.20 2009/11/11 16:47:50 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@@ -29,9 +29,10 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ltsleep.c,v 1.19 2009/10/15 00:28:46 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ltsleep.c,v 1.20 2009/11/11 16:47:50 pooka Exp $");
#include <sys/param.h>
+#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/queue.h>
#include <sys/simplelock.h>
@@ -50,32 +51,49 @@
kcondvar_t lbolt; /* Oh Kath Ra */
+static int
+sleeper(struct ltsleeper *ltsp, int timo)
+{
+ int rv, nlocks;
+
+ LIST_INSERT_HEAD(&sleepers, ltsp, entries);
+ kernel_unlock_allbutone(&nlocks);
+
+ /* protected by biglock */
+ if (timo) {
+ rv = rumpuser_cv_timedwait(ltsp->cv, rump_giantlock,
+ timo / hz, (timo % hz) * (1000000000/hz));
+ } else {
+ rumpuser_cv_wait(ltsp->cv, rump_giantlock);
+ rv = 0;
+ }
+
+ LIST_REMOVE(ltsp, entries);
+ rumpuser_cv_destroy(ltsp->cv);
+ kernel_ununlock_allbutone(nlocks);
+
+ return rv;
+}
+
int
ltsleep(wchan_t ident, pri_t prio, const char *wmesg, int timo,
volatile struct simplelock *slock)
{
struct ltsleeper lts;
- int nlocks;
+ int rv;
lts.id = ident;
rumpuser_cv_init(<s.cv);
if (slock)
simple_unlock(slock);
- LIST_INSERT_HEAD(&sleepers, <s, entries);
- kernel_unlock_allbutone(&nlocks);
- /* protected by biglock */
- rumpuser_cv_wait(lts.cv, rump_giantlock);
-
- LIST_REMOVE(<s, entries);
- rumpuser_cv_destroy(lts.cv);
- kernel_ununlock_allbutone(nlocks);
+ rv = sleeper(<s, timo);
if (slock && (prio & PNORELOCK) == 0)
simple_lock(slock);
- return 0;
+ return rv;
}
int
@@ -83,26 +101,19 @@
kmutex_t *lock)
{
struct ltsleeper lts;
- int nlocks;
+ int rv;
lts.id = ident;
rumpuser_cv_init(<s.cv);
mutex_exit(lock);
- LIST_INSERT_HEAD(&sleepers, <s, entries);
- kernel_unlock_allbutone(&nlocks);
-
- /* protected by biglock */
- rumpuser_cv_wait(lts.cv, rump_giantlock);
- LIST_REMOVE(<s, entries);
- rumpuser_cv_destroy(lts.cv);
- kernel_ununlock_allbutone(nlocks);
+ rv = sleeper(<s, timo);
if ((prio & PNORELOCK) == 0)
mutex_enter(lock);
- return 0;
+ return rv;
}
static void