summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2000-11-15 22:39:35 +0000
committerjhb <jhb@FreeBSD.org>2000-11-15 22:39:35 +0000
commitde636b04e8d3f784a9cec070dd3f6a60142972a0 (patch)
tree54a7413fa750eff65d272275f1b47de4d571d7d0 /sys
parent0efbfa0260e20fd09ec20131b349b2b2abe0ec93 (diff)
downloadFreeBSD-src-de636b04e8d3f784a9cec070dd3f6a60142972a0.zip
FreeBSD-src-de636b04e8d3f784a9cec070dd3f6a60142972a0.tar.gz
- Rename await() to mawait(). mawait() is to await() as msleep() is to
tsleep(). Namely, mawait() takes an extra argument which is a mutex to drop when going to sleep. Just as with msleep(), if the priority argument includes the PDROP flag, then the mutex will be dropped and will not be reacquired when the process wakes up. - Add in a backwards compatible macro await() that passes in NULL as the mutex argument to mawait().
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_synch.c41
-rw-r--r--sys/sys/systm.h3
2 files changed, 29 insertions, 15 deletions
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index 3d7f6f4..3f04391 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -537,16 +537,16 @@ out:
/*
* asleep() - async sleep call. Place process on wait queue and return
- * immediately without blocking. The process stays runnable until await()
+ * immediately without blocking. The process stays runnable until mawait()
* is called. If ident is NULL, remove process from wait queue if it is still
* on one.
*
* Only the most recent sleep condition is effective when making successive
* calls to asleep() or when calling msleep().
*
- * The timeout, if any, is not initiated until await() is called. The sleep
+ * The timeout, if any, is not initiated until mawait() is called. The sleep
* priority, signal, and timeout is specified in the asleep() call but may be
- * overriden in the await() call.
+ * overriden in the mawait() call.
*
* <<<<<<<< EXPERIMENTAL, UNTESTED >>>>>>>>>>
*/
@@ -586,25 +586,34 @@ asleep(void *ident, int priority, const char *wmesg, int timo)
}
/*
- * await() - wait for async condition to occur. The process blocks until
+ * mawait() - wait for async condition to occur. The process blocks until
* wakeup() is called on the most recent asleep() address. If wakeup is called
- * prior to await(), await() winds up being a NOP.
+ * prior to mawait(), mawait() winds up being a NOP.
*
- * If await() is called more then once (without an intervening asleep() call),
- * await() is still effectively a NOP but it calls mi_switch() to give other
+ * If mawait() is called more then once (without an intervening asleep() call),
+ * mawait() is still effectively a NOP but it calls mi_switch() to give other
* processes some cpu before returning. The process is left runnable.
*
* <<<<<<<< EXPERIMENTAL, UNTESTED >>>>>>>>>>
*/
int
-await(int priority, int timo)
+mawait(struct mtx *mtx, int priority, int timo)
{
struct proc *p = curproc;
int rval = 0;
int s;
+ WITNESS_SAVE_DECL(mtx);
+ WITNESS_SLEEP(0, mtx);
mtx_enter(&sched_lock, MTX_SPIN);
+ if (mtx != NULL) {
+ mtx_assert(mtx, MA_OWNED | MA_NOTRECURSED);
+ WITNESS_SAVE(mtx, mtx);
+ mtx_exit(mtx, MTX_DEF | MTX_NOSWITCH);
+ if (priority & PDROP)
+ mtx = NULL;
+ }
s = splhigh();
@@ -614,7 +623,7 @@ await(int priority, int timo)
int catch;
/*
- * The call to await() can override defaults specified in
+ * The call to mawait() can override defaults specified in
* the original asleep().
*/
if (priority < 0)
@@ -682,7 +691,7 @@ resume:
#endif
} else {
/*
- * If as_priority is 0, await() has been called without an
+ * If as_priority is 0, mawait() has been called without an
* intervening asleep(). We are still effectively a NOP,
* but we call mi_switch() for safety.
*/
@@ -695,9 +704,9 @@ resume:
}
/*
- * clear p_asleep.as_priority as an indication that await() has been
- * called. If await() is called again without an intervening asleep(),
- * await() is still effectively a NOP but the above mi_switch() code
+ * clear p_asleep.as_priority as an indication that mawait() has been
+ * called. If mawait() is called again without an intervening asleep(),
+ * mawait() is still effectively a NOP but the above mi_switch() code
* is triggered as a safety.
*/
p->p_asleep.as_priority = 0;
@@ -705,11 +714,15 @@ resume:
out:
mtx_exit(&sched_lock, MTX_SPIN);
+ if (mtx != NULL) {
+ mtx_enter(mtx, MTX_DEF);
+ WITNESS_RESTORE(mtx, mtx);
+ }
return (rval);
}
/*
- * Implement timeout for msleep or asleep()/await()
+ * Implement timeout for msleep or asleep()/mawait()
*
* If process hasn't been awakened (wchan non-zero),
* set timeout flag and undo the sleep. If proc
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index 37b5fe3..55b2a22 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -283,7 +283,8 @@ int msleep __P((void *chan, struct mtx *mtx, int pri, const char *wmesg,
int timo));
#define tsleep(chan, pri, wmesg, timo) msleep(chan, NULL, pri, wmesg, timo)
int asleep __P((void *chan, int pri, const char *wmesg, int timo));
-int await __P((int pri, int timo));
+#define await(pri, timo) mawait(NULL, pri, timo)
+int mawait __P((struct mtx *mtx, int pri, int timo));
void wakeup __P((void *chan));
void wakeup_one __P((void *chan));
OpenPOWER on IntegriCloud