diff --git a/src/jrd/GlobalRWLock.cpp b/src/jrd/GlobalRWLock.cpp index f7a975bbea..983dee9259 100644 --- a/src/jrd/GlobalRWLock.cpp +++ b/src/jrd/GlobalRWLock.cpp @@ -38,6 +38,7 @@ #include "Attachment.h" #include "../common/classes/rwlock.h" #include "../common/classes/condition.h" +#include "../common/classes/auto.h" #ifdef COS_DEBUG #include @@ -179,12 +180,20 @@ bool GlobalRWLock::lockWrite(thread_db* tdbb, SSHORT wait) fb_assert(!currentWriter); - currentWriter = true; + Cleanup writerFini([this]() + { + if (!currentWriter) + writerFinished.notifyAll(); + }); + + const bool ret = fetch(tdbb); + if (ret) + currentWriter = true; COS_TRACE(("(%p)->lockWrite end readers(%d), blocking(%d), pendingWriters(%d), currentWriter(%d), lck_physical(%d)", this, readers, blocking, pendingWriters, currentWriter, cachedLock->lck_physical)); - return fetch(tdbb); + return ret; } } @@ -279,12 +288,14 @@ bool GlobalRWLock::lockRead(thread_db* tdbb, SSHORT wait, const bool queueJump) { // scope 2 CheckoutLockGuard counterGuard(tdbb, counterMutex, FB_FUNCTION, true); --pendingLock; - ++readers; + const bool ret = fetch(tdbb); + if (ret) + ++readers; COS_TRACE(("(%p)->lockRead end readers(%d), blocking(%d), pendingWriters(%d), currentWriter(%d), lck_physical(%d)", this, readers, blocking, pendingWriters, currentWriter, cachedLock->lck_physical)); - return fetch(tdbb); + return ret; } }