From 401f7aaf8a4b36c5409b47caeb111224c19cfa64 Mon Sep 17 00:00:00 2001 From: jhb Date: Fri, 23 Feb 2007 16:22:09 +0000 Subject: Add a new kernel sleep function pause(9). pause(9) is for places that want an equivalent of DELAY(9) that sleeps instead of spins. It accepts a wmesg and a timeout and is not interrupted by signals. It uses a private wait channel that should never be woken up by wakeup(9) or wakeup_one(9). Glanced at by: phk --- sys/kern/kern_synch.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'sys/kern/kern_synch.c') diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 6cc7c70..089919c 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -69,6 +69,7 @@ SYSINIT(synch_setup, SI_SUB_KICK_SCHEDULER, SI_ORDER_FIRST, synch_setup, NULL) int hogticks; int lbolt; +static int pause_wchan; static struct callout loadav_callout; static struct callout lbolt_callout; @@ -164,7 +165,10 @@ msleep(ident, mtx, priority, wmesg, timo) if (TD_ON_SLEEPQ(td)) sleepq_remove(td, td->td_wchan); - flags = SLEEPQ_MSLEEP; + if (ident == &pause_wchan) + flags = SLEEPQ_PAUSE; + else + flags = SLEEPQ_MSLEEP; if (catch) flags |= SLEEPQ_INTERRUPTIBLE; @@ -308,6 +312,22 @@ msleep_spin(ident, mtx, wmesg, timo) } /* + * pause() is like tsleep() except that the intention is to not be + * explicitly woken up by another thread. Instead, the current thread + * simply wishes to sleep until the timeout expires. It is + * implemented using a dummy wait channel. + */ +int +pause(wmesg, timo) + const char *wmesg; + int timo; +{ + + KASSERT(timo != 0, ("pause: timeout required")); + return (tsleep(&pause_wchan, 0, wmesg, timo)); +} + +/* * Make all threads sleeping on the specified identifier runnable. */ void -- cgit v1.1