From a57ac8ec23ba4df071c090a1d61707a997b1727c Mon Sep 17 00:00:00 2001 From: dimitr Date: Tue, 27 Mar 2012 07:11:34 +0000 Subject: [PATCH] Optimized the shared counter generator to avoid LM calls if there's no contention on the protecting lock. --- src/jrd/Database.cpp | 8 +++++++- src/jrd/Database.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) 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; };