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
This commit is contained in:
Andrew Gallatin 2021-08-05 17:16:30 -04:00
parent 8482aa7748
commit 1b97a054f3
2 changed files with 4 additions and 2 deletions

View File

@ -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"));

View File

@ -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" */