aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gallatin <gallatin@FreeBSD.org>2021-08-05 21:16:30 +0000
committerAndrew Gallatin <gallatin@FreeBSD.org>2021-08-05 21:16:30 +0000
commit1b97a054f3acaf13a5c8361b7b80e10ad16257b9 (patch)
treec52f42c863ea8d01fe6a7776a38f0caff75247a2
parent8482aa77481a1576df7a19dbeaccb91243fbb2a3 (diff)
tsleep: Add a PNOLOCK flag
Add a PNOLOCK flag so that, in the race circumstance where wakeup races are externally mitigated, tsleep() can be called with a sleep time of 0 without triggering an an assertion. Reviewed by: jhb Sponsored by: Netflix
-rw-r--r--sys/kern/kern_synch.c3
-rw-r--r--sys/sys/param.h3
2 files changed, 4 insertions, 2 deletions
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index 793c5309a30b..7bf5193fb7b1 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -148,7 +148,8 @@ _sleep(const void *ident, struct lock_object *lock, int priority,
#endif
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, lock,
"Sleeping on \"%s\"", wmesg);
- KASSERT(sbt != 0 || mtx_owned(&Giant) || lock != NULL,
+ KASSERT(sbt != 0 || mtx_owned(&Giant) || lock != NULL ||
+ (priority & PNOLOCK) != 0,
("sleeping without a lock"));
KASSERT(ident != NULL, ("_sleep: NULL ident"));
KASSERT(TD_IS_RUNNING(td), ("_sleep: curthread not running"));
diff --git a/sys/sys/param.h b/sys/sys/param.h
index f842b344e9f9..8864063e3d9b 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -246,7 +246,8 @@
#define PRIMASK 0x0ff
#define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */
#define PDROP 0x200 /* OR'd with pri to stop re-entry of interlock mutex */
-#define PRILASTFLAG 0x200 /* Last flag defined above */
+#define PNOLOCK 0x400 /* OR'd with pri to allow sleeping w/o a lock */
+#define PRILASTFLAG 0x400 /* Last flag defined above */
#define NZERO 0 /* default "nice" */