diff --git a/src/system/kernel/locks/lock.cpp b/src/system/kernel/locks/lock.cpp index bb2fe98df0..067b73d08b 100644 --- a/src/system/kernel/locks/lock.cpp +++ b/src/system/kernel/locks/lock.cpp @@ -512,6 +512,7 @@ _rw_lock_read_lock(rw_lock* lock) #if KDEBUG_RW_LOCK_DEBUG int32 oldCount = atomic_add(&lock->count, 1); if (oldCount < RW_LOCK_WRITER_COUNT_BASE) { + ASSERT_UNLOCKED_RW_LOCK(lock); _rw_lock_set_read_locked(lock); return B_OK; } @@ -525,6 +526,10 @@ _rw_lock_read_lock(rw_lock* lock) return B_OK; } + // If we hold a read lock already, but some other thread is waiting + // for a write lock, then trying to read-lock again will deadlock. + ASSERT_UNLOCKED_RW_LOCK(lock); + // The writer that originally had the lock when we called atomic_add() might // already have gone and another writer could have overtaken us. In this // case the original writer set pending_readers, so we know that we don't