From db571b4859fc90709b8774ee2d7e7a1deb950ddc Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sat, 28 Jun 2025 16:46:49 +0300 Subject: [PATCH] Kernel: Allow relockign mutex even when holding a spinlock Only reason mutex locking is now allowed with spinlocks is to prevent yield. Also try_lock can be now safely used while holding a spinlock --- kernel/include/kernel/Lock/Mutex.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/include/kernel/Lock/Mutex.h b/kernel/include/kernel/Lock/Mutex.h index c199f805..04cf979f 100644 --- a/kernel/include/kernel/Lock/Mutex.h +++ b/kernel/include/kernel/Lock/Mutex.h @@ -32,11 +32,11 @@ namespace Kernel void lock() override { const auto tid = Thread::current_tid(); - ASSERT(!tid || !Thread::current().has_spinlock()); if (tid == m_locker) ASSERT(m_lock_depth > 0); else { + ASSERT(!tid || !Thread::current().has_spinlock()); pid_t expected = -1; while (!m_locker.compare_exchange(expected, tid)) { @@ -53,7 +53,6 @@ namespace Kernel bool try_lock() override { const auto tid = Thread::current_tid(); - ASSERT(!tid || !Thread::current().has_spinlock()); if (tid == m_locker) ASSERT(m_lock_depth > 0); else @@ -102,12 +101,12 @@ namespace Kernel void lock() override { const auto tid = Thread::current_tid(); - ASSERT(!tid || !Thread::current().has_spinlock()); if (tid == m_locker) ASSERT(m_lock_depth > 0); else { + ASSERT(!tid || !Thread::current().has_spinlock()); bool has_priority = tid ? !Thread::current().is_userspace() : true; if (has_priority) m_queue_length++; @@ -127,7 +126,6 @@ namespace Kernel bool try_lock() override { const auto tid = Thread::current_tid(); - ASSERT(!tid || !Thread::current().has_spinlock()); if (tid == m_locker) ASSERT(m_lock_depth > 0);