Index: sys/sys/proc.h =================================================================== --- sys/sys/proc.h (revision 247554) +++ sys/sys/proc.h (working copy) @@ -273,6 +273,7 @@ struct thread { struct vm_map_entry *td_map_def_user; /* (k) Deferred entries. */ pid_t td_dbg_forked; /* (c) Child pid for debugger. */ u_int td_vp_reserv; /* (k) Count of reserved vnodes. */ + u_int td_no_sleeping; /* (k) Sleeping disabled count. */ #define td_endzero td_sigmask /* Copied during fork1() or create_thread(). */ @@ -404,7 +405,7 @@ do { \ #define TDP_ALTSTACK 0x00000020 /* Have alternate signal stack. */ #define TDP_DEADLKTREAT 0x00000040 /* Lock aquisition - deadlock treatment. */ #define TDP_NOFAULTING 0x00000080 /* Do not handle page faults. */ -#define TDP_NOSLEEPING 0x00000100 /* Thread is not allowed to sleep on a sq. */ +#define TDP_UNUSED09 0x00000100 /* --available-- */ #define TDP_OWEUPC 0x00000200 /* Call addupc() at next AST. */ #define TDP_ITHREAD 0x00000400 /* Thread is an interrupt thread. */ #define TDP_SYNCIO 0x00000800 /* Local override, disable async i/o. */ @@ -790,17 +791,9 @@ extern pid_t pid_max; #define thread_safetoswapout(td) ((td)->td_flags & TDF_CANSWAP) /* Control whether or not it is safe for curthread to sleep. */ -#define THREAD_NO_SLEEPING() do { \ - KASSERT(!(curthread->td_pflags & TDP_NOSLEEPING), \ - ("nested no sleeping")); \ - curthread->td_pflags |= TDP_NOSLEEPING; \ -} while (0) +#define THREAD_NO_SLEEPING() (curthread->td_no_sleeping++) -#define THREAD_SLEEPING_OK() do { \ - KASSERT((curthread->td_pflags & TDP_NOSLEEPING), \ - ("nested sleeping ok")); \ - curthread->td_pflags &= ~TDP_NOSLEEPING; \ -} while (0) +#define THREAD_SLEEPING_OK() (curthread->td_no_sleeping--) #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash]) extern LIST_HEAD(pidhashhead, proc) *pidhashtbl; Index: sys/kern/subr_trap.c =================================================================== --- sys/kern/subr_trap.c (revision 247554) +++ sys/kern/subr_trap.c (working copy) @@ -158,7 +158,7 @@ userret(struct thread *td, struct trapframe *frame ("userret: Returning with %d locks held", td->td_locks)); KASSERT((td->td_pflags & TDP_NOFAULTING) == 0, ("userret: Returning with pagefaults disabled")); - KASSERT((td->td_pflags & TDP_NOSLEEPING) == 0, + KASSERT(td->td_no_sleeping == 0, ("userret: Returning with sleep disabled")); KASSERT(td->td_pinned == 0 || (td->td_pflags & TDP_CALLCHAIN) != 0, ("userret: Returning with with pinned thread")); Index: sys/kern/subr_sleepqueue.c =================================================================== --- sys/kern/subr_sleepqueue.c (revision 247554) +++ sys/kern/subr_sleepqueue.c (working copy) @@ -296,8 +296,8 @@ sleepq_add(void *wchan, struct lock_object *lock, MPASS((queue >= 0) && (queue < NR_SLEEPQS)); /* If this thread is not allowed to sleep, die a horrible death. */ - KASSERT(!(td->td_pflags & TDP_NOSLEEPING), - ("%s: td %p to sleep on wchan %p with TDP_NOSLEEPING on", + KASSERT(td->td_no_sleeping == 0, + ("%s: td %p to sleep on wchan %p when sleeps are forbidden", __func__, td, wchan)); /* Look up the sleep queue associated with the wait channel 'wchan'. */ Index: sys/dev/mps/mps.c =================================================================== --- sys/dev/mps/mps.c (revision 247554) +++ sys/dev/mps/mps.c (working copy) @@ -137,7 +137,7 @@ mps_diag_reset(struct mps_softc *sc,int sleep_flag /*Force NO_SLEEP for threads prohibited to sleep * e.a Thread from interrupt handler are prohibited to sleep. */ - if(curthread->td_pflags & TDP_NOSLEEPING) + if(curthread->td_no_sleeping != 0) sleep_flag = NO_SLEEP; /* Push the magic sequence */ @@ -470,7 +470,7 @@ mps_request_sync(struct mps_softc *sc, void *req, int i, count, ioc_sz, residual; int sleep_flags = CAN_SLEEP; - if(curthread->td_pflags & TDP_NOSLEEPING) + if(curthread->td_no_sleeping != 0) sleep_flags = NO_SLEEP; /* Step 1 */