From dd45194d37bb3b2f96f0c7c57fcc07fe2e5b8535 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 10 Sep 2024 17:24:57 -0400 Subject: [PATCH] kernel/lock: Adjust KDEBUG_RW_LOCK_DEBUG logic in _rw_lock_read_unlock. We need to always decrement the count by 1 even if we own the lock. Seems to fix some intermittent hangs with KDEBUG_RW_LOCK_DEBUG. --- src/system/kernel/locks/lock.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/system/kernel/locks/lock.cpp b/src/system/kernel/locks/lock.cpp index 10c4b57cb6..b501f567d3 100644 --- a/src/system/kernel/locks/lock.cpp +++ b/src/system/kernel/locks/lock.cpp @@ -669,22 +669,26 @@ _rw_lock_read_lock_with_timeout(rw_lock* lock, uint32 timeoutFlags, void _rw_lock_read_unlock(rw_lock* lock) { +#if KDEBUG_RW_LOCK_DEBUG + int32 oldCount = atomic_add(&lock->count, -1); + if (oldCount < RW_LOCK_WRITER_COUNT_BASE) { + _rw_lock_unset_read_locked(lock); + return; + } +#endif + InterruptsSpinLocker locker(lock->lock); // If we're still holding the write lock or if there are other readers, // no-one can be woken up. if (lock->holder == thread_get_current_thread_id()) { - ASSERT(lock->owner_count % RW_LOCK_WRITER_COUNT_BASE > 0); + ASSERT((lock->owner_count % RW_LOCK_WRITER_COUNT_BASE) > 0); lock->owner_count--; return; } #if KDEBUG_RW_LOCK_DEBUG _rw_lock_unset_read_locked(lock); - - int32 oldCount = atomic_add(&lock->count, -1); - if (oldCount < RW_LOCK_WRITER_COUNT_BASE) - return; #endif if (--lock->active_readers > 0)