Fix a bug in isc_rwlock_trylock()

When isc_rwlock_trylock() fails to get a read lock because another
writer was faster, it should wake up other waiting writers in case
there are no other readers, but the current code forgets about
the currently active writer when evaluating 'cntflag'.

Unset the WRITER_ACTIVE bit in 'cntflag' before checking to see if
there are other readers, otherwise the waiting writers, if they exist,
might not wake up.
This commit is contained in:
Aram Sargsyan
2025-01-07 13:30:26 +00:00
parent 333834e764
commit 73b6d9e9e5
+2 -1
View File
@@ -472,7 +472,8 @@ isc_rwlock_trylock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
* request.
*/
cntflag = atomic_fetch_sub_release(&rwl->cnt_and_flag,
READER_INCR);
READER_INCR) &
~WRITER_ACTIVE;
/*
* If no other readers are waiting and we've suspended
* new writers in this short period, wake them up.