8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 22:43:03 +01:00

GlobalRWLock state should remain consistent in the case when fetch() returns false or throws.

This commit is contained in:
Vlad Khorsun 2024-03-12 12:57:20 +02:00 committed by Dmitry Yemanov
parent ebcd4dde64
commit 44579459ec

View File

@ -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 <stdarg.h>
@ -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;
}
}