Skip to content

Commit

Permalink
fix: dev: Fix a bug in isc_rwlock_trylock()
Browse files Browse the repository at this point in the history
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.

Closes #5121

Merge branch 'aram/isc_rwlock_trylock-bugfix-9.18' into 'bind-9.18'

See merge request isc-projects/bind9!9937
  • Loading branch information
Arаm Sаrgsyаn committed Jan 8, 2025
2 parents 333834e + 73b6d9e commit f68e60b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/isc/rwlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f68e60b

Please sign in to comment.