summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_synch.c
diff options
context:
space:
mode:
authorjake <jake@FreeBSD.org>2000-09-11 00:20:02 +0000
committerjake <jake@FreeBSD.org>2000-09-11 00:20:02 +0000
commit273d0f5a2d56ee17d75e7a16ad23d0a40ee6a0f0 (patch)
treed266af83e80b070d300be67ec6d4ff696f8a7393 /sys/kern/kern_synch.c
parent7a63f3f75c0fa73d989787cc3df1adfdc597b86f (diff)
downloadFreeBSD-src-273d0f5a2d56ee17d75e7a16ad23d0a40ee6a0f0.zip
FreeBSD-src-273d0f5a2d56ee17d75e7a16ad23d0a40ee6a0f0.tar.gz
Rename tsleep to msleep and add a mutex argument, which is
released before sleeping and re-acquired before msleep returns. A compatibility cpp macro has been provided for tsleep to avoid changing all occurences of it in the kernel. Remove an assertion that the Giant mutex be held before calling tsleep or asleep. This is intended to serve the same purpose as condition variables, but does not preclude their addition in the future. Approved by: jasone Obtained from: BSD/OS
Diffstat (limited to 'sys/kern/kern_synch.c')
-rw-r--r--sys/kern/kern_synch.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index 6c53f8f..cd41140 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -408,10 +408,15 @@ sleepinit(void)
* signal needs to be delivered, ERESTART is returned if the current system
* call should be restarted if possible, and EINTR is returned if the system
* call should be interrupted by the signal (return EINTR).
+ *
+ * The mutex argument is exited before the caller is suspended, and
+ * entered before msleep returns. If priority includes the PDROP
+ * flag the mutex is not entered before returning.
*/
int
-tsleep(ident, priority, wmesg, timo)
+msleep(ident, mtx, priority, wmesg, timo)
void *ident;
+ mtx_t *mtx;
int priority, timo;
const char *wmesg;
{
@@ -419,14 +424,22 @@ tsleep(ident, priority, wmesg, timo)
int s, sig, catch = priority & PCATCH;
struct callout_handle thandle;
int rval = 0;
+ WITNESS_SAVE_DECL(mtx);
#ifdef KTRACE
if (p && KTRPOINT(p, KTR_CSW))
ktrcsw(p->p_tracep, 1, 0);
#endif
- mtx_assert(&Giant, MA_OWNED);
+ WITNESS_SLEEP(0, mtx);
mtx_enter(&sched_lock, MTX_SPIN);
+ if (mtx != NULL) {
+ WITNESS_SAVE(mtx, mtx);
+ mtx_exit(mtx, MTX_DEF | MTX_NOSWITCH);
+ if (priority & PDROP)
+ mtx = NULL;
+ }
+
s = splhigh();
if (cold || panicstr) {
/*
@@ -527,7 +540,10 @@ out:
if (KTRPOINT(p, KTR_CSW))
ktrcsw(p->p_tracep, 0, 0);
#endif
-
+ if (mtx != NULL) {
+ mtx_enter(mtx, MTX_DEF);
+ WITNESS_RESTORE(mtx, mtx);
+ }
return (rval);
}
@@ -600,7 +616,6 @@ await(int priority, int timo)
int rval = 0;
int s;
- mtx_assert(&Giant, MA_OWNED);
mtx_enter(&sched_lock, MTX_SPIN);
s = splhigh();
OpenPOWER on IntegriCloud