]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix a bug in isc_rwlock_trylock()
authorAram Sargsyan <aram@isc.org>
Tue, 7 Jan 2025 13:30:26 +0000 (13:30 +0000)
committerArаm Sаrgsyаn <aram@isc.org>
Wed, 8 Jan 2025 10:30:05 +0000 (10:30 +0000)
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.

(cherry picked from commit 73b6d9e9e5c3405b8f2cd6ab1e999e2a5d756875)

lib/isc/rwlock.c

index c69b6d7550bcff9161b82f18cb2a1c1ebff1c731..aa1156555db3d56a9f93ffcbe00d40429337f0d0 100644 (file)
@@ -475,7 +475,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.