diff --git a/src/jrd/Database.cpp b/src/jrd/Database.cpp index 99631b3ace..2ca189d26b 100644 --- a/src/jrd/Database.cpp +++ b/src/jrd/Database.cpp @@ -155,13 +155,18 @@ namespace Jrd lock->lck_object = counter; LCK_lock(tdbb, lock, LCK_PW, LCK_WAIT); + counter->isProtected = true; counter->curVal = 1; counter->maxVal = 0; } if (counter->curVal > counter->maxVal) { - LCK_convert(tdbb, counter->lock, LCK_PW, LCK_WAIT); + if (!counter->isProtected) + { + LCK_convert(tdbb, counter->lock, LCK_PW, LCK_WAIT); + counter->isProtected = true; + } counter->curVal = LCK_read_data(tdbb, counter->lock); @@ -196,6 +201,7 @@ namespace Jrd Jrd::ContextPoolHolder context(tdbb, dbb->dbb_permanent); LCK_downgrade(tdbb, counter->lock); + counter->isProtected = false; } catch (const Firebird::Exception&) {} // no-op diff --git a/src/jrd/Database.h b/src/jrd/Database.h index b35e72703b..cfefbe6a31 100644 --- a/src/jrd/Database.h +++ b/src/jrd/Database.h @@ -287,6 +287,7 @@ public: struct ValueCache { Lock* lock; + bool isProtected; SLONG curVal; SLONG maxVal; };