From 5879781c77ac5ed903b3712aef546848681b449d Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 12 Aug 2023 13:29:32 +0200 Subject: kern: Check that locking thread is done at spl7 --- kern/thread.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/kern/thread.h b/kern/thread.h index 3485f6af..8547464d 100644 --- a/kern/thread.h +++ b/kern/thread.h @@ -392,8 +392,19 @@ extern void thread_unfreeze( #define thread_pcb(th) ((th)->pcb) /* Shall be taken at splsched only */ -#define thread_lock(th) simple_lock(&(th)->lock) -#define thread_unlock(th) simple_unlock(&(th)->lock) +#ifdef MACH_LDEBUG +#define thread_lock(th) do { \ + assert(splsched() == SPL7); \ + simple_lock_nocheck(&(th)->lock); \ +} while (0) +#define thread_unlock(th) do { \ + assert(splsched() == SPL7); \ + simple_unlock_nocheck(&(th)->lock); \ +} while (0) +#else +#define thread_lock(th) simple_lock_nocheck(&(th)->lock) +#define thread_unlock(th) simple_unlock_nocheck(&(th)->lock) +#endif #define thread_should_halt(thread) \ ((thread)->ast & (AST_HALT|AST_TERMINATE)) -- cgit v1.2.3