kernel/lock: Reinstate ASSERT_UNLOCKED_RW_LOCK in _rw_lock_read_lock.

This reverts commit 13a5c7f91f,
and adds an inline comment explaining why this actually isn't allowed,
despite "working" in most circumstances.

Doesn't affect anything in default builds (KDEBUG_RW_LOCK_DEBUG
is not enabled under KDEBUG.)
This commit is contained in:
Augustin Cavalier 2024-10-09 16:16:35 -04:00
parent bc89edc3c3
commit 6dae8511ff

View File

@ -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