--- Gnu-Mach/kern/sched_prim.c 2020/09/02 04:47:23 1.1.1.4 +++ Gnu-Mach/kern/sched_prim.c 2020/09/02 04:53:59 1.1.1.7 @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include #include @@ -357,12 +357,17 @@ void clear_wait( splx(s); } -static inline void __attribute__((noreturn)) -state_panic(const thread_t thread, const char *caller) -{ - panic ("%s: thread %x has unexpected state %x", - caller, thread, thread->state); -} +#define state_panic(thread) \ + panic ("thread %p has unexpected state %x (%s%s%s%s%s%s%s%s)", \ + thread, thread->state, \ + thread->state & TH_WAIT ? "TH_WAIT|" : "", \ + thread->state & TH_SUSP ? "TH_SUSP|" : "", \ + thread->state & TH_RUN ? "TH_RUN|" : "", \ + thread->state & TH_UNINT ? "TH_UNINT|" : "", \ + thread->state & TH_HALTED ? "TH_HALTED|" : "", \ + thread->state & TH_IDLE ? "TH_IDLE|" : "", \ + thread->state & TH_SWAPPED ? "TH_SWAPPED|" : "", \ + thread->state & TH_SW_COMING_IN ? "TH_SW_COMING_IN|" : "") /* * thread_wakeup_prim: @@ -426,7 +431,7 @@ void thread_wakeup_prim( break; default: - state_panic(thread, "thread_wakeup"); + state_panic(thread); break; } thread_unlock(thread); @@ -446,6 +451,9 @@ void thread_wakeup_prim( * occurs. The specified lock is unlocked before releasing * the cpu. (This is a convenient way to sleep without manually * calling assert_wait). + * + * Note: if the event may be woken from an interrupt handler, this must be + * called at an spl level that prevents such interrupts. */ void thread_sleep( event_t event, @@ -454,7 +462,7 @@ void thread_sleep( { assert_wait(event, interruptible); /* assert event */ simple_unlock(lock); /* release the lock */ - thread_block((void (*)()) 0); /* block ourselves */ + thread_block(thread_no_continuation); /* block ourselves */ } /* @@ -617,7 +625,7 @@ boolean_t thread_invoke( thread_unlock(new_thread); thread_wakeup(TH_EV_STATE(new_thread)); - if (continuation != (void (*)()) 0) { + if (continuation != thread_no_continuation) { (void) spl0(); call_continuation(continuation); /*NOTREACHED*/ @@ -630,7 +638,7 @@ boolean_t thread_invoke( */ thread_lock(new_thread); if ((old_thread->stack_privilege != current_stack()) && - (continuation != (void (*)()) 0)) + (continuation != thread_no_continuation)) { switch (new_thread->state & TH_SWAP_STATE) { case TH_SWAPPED: @@ -713,7 +721,7 @@ boolean_t thread_invoke( break; default: - state_panic(old_thread, "thread_invoke"); + state_panic(old_thread); } thread_unlock(old_thread); after_old_thread: @@ -915,7 +923,7 @@ void thread_dispatch( thread_lock(thread); - if (thread->swap_func != (void (*)()) 0) { + if (thread->swap_func != thread_no_continuation) { assert((thread->state & TH_SWAP_STATE) == 0); thread->state |= TH_SWAPPED; stack_free(thread); @@ -963,7 +971,7 @@ void thread_dispatch( break; default: - state_panic(thread, "thread_dispatch"); + state_panic(thread); } thread_unlock(thread); }