> Date: Wed, 23 Dec 2020 14:59:02 -0600 > From: Scott Cheloha <scottchel...@gmail.com> > > Okay, let's try one more time. > > This patch adds a global sleep channel, "nowake", for sleeping threads > that don't want to receive wakeup(9) broadcasts. > > You use it like this: > > #include <sys/systm.h> > > tsleep(nowake, ...); > > I've added additional assertions to tsleep, msleep, and rwsleep that > ensures that there is *some* way to wake up the thread. You need > either an ident that is not nowake, PCATCH, or a timeout. > > I prefer using indirection here to save a character when using it as > the ident, i.e. "nowake" is shorter than "&nowake".
I disagree. &nowake is obvious and doesn't require the weird underscored symbol indirection. > I'll document it when it is used more broadly in the kernel. > > ok? > > Index: kern/kern_synch.c > =================================================================== > RCS file: /cvs/src/sys/kern/kern_synch.c,v > retrieving revision 1.172 > diff -u -p -r1.172 kern_synch.c > --- kern/kern_synch.c 7 Dec 2020 16:55:29 -0000 1.172 > +++ kern/kern_synch.c 23 Dec 2020 20:56:35 -0000 > @@ -87,6 +87,12 @@ sleep_queue_init(void) > TAILQ_INIT(&slpque[i]); > } > > +/* > + * nowake is a global sleep channel for threads that do not want > + * to receive wakeup(9) broadcasts. > + */ > +int __nowake; > +void *nowake = &__nowake; > > /* > * During autoconfiguration or after a panic, a sleep will simply > @@ -119,6 +125,7 @@ tsleep(const volatile void *ident, int p > #endif > > KASSERT((priority & ~(PRIMASK | PCATCH)) == 0); > + KASSERT(ident != nowake || ISSET(priority, PCATCH) || timo != 0); > > #ifdef MULTIPROCESSOR > KASSERT(timo || _kernel_lock_held()); > @@ -213,6 +220,7 @@ msleep(const volatile void *ident, struc > #endif > > KASSERT((priority & ~(PRIMASK | PCATCH | PNORELOCK)) == 0); > + KASSERT(ident != nowake || ISSET(priority, PCATCH) || timo != 0); > KASSERT(mtx != NULL); > > if (priority & PCATCH) > @@ -301,6 +309,7 @@ rwsleep(const volatile void *ident, stru > int error, status; > > KASSERT((priority & ~(PRIMASK | PCATCH | PNORELOCK)) == 0); > + KASSERT(ident != nowake || ISSET(priority, PCATCH) || timo != 0); > rw_assert_anylock(rwl); > status = rw_status(rwl); > > Index: sys/systm.h > =================================================================== > RCS file: /cvs/src/sys/sys/systm.h,v > retrieving revision 1.148 > diff -u -p -r1.148 systm.h > --- sys/systm.h 26 Aug 2020 03:29:07 -0000 1.148 > +++ sys/systm.h 23 Dec 2020 20:56:35 -0000 > @@ -107,6 +107,8 @@ extern struct vnode *rootvp; /* vnode eq > extern dev_t swapdev; /* swapping device */ > extern struct vnode *swapdev_vp;/* vnode equivalent to above */ > > +extern void *nowake; /* dead wakeup(9) channel */ > + > struct proc; > struct process; > #define curproc curcpu()->ci_curproc > >