mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-24 03:23:03 +01:00
Optimized the shared counter generator to avoid LM calls if there's no contention on the protecting lock.
This commit is contained in:
parent
e085f6008f
commit
a57ac8ec23
@ -155,13 +155,18 @@ namespace Jrd
|
|||||||
lock->lck_object = counter;
|
lock->lck_object = counter;
|
||||||
LCK_lock(tdbb, lock, LCK_PW, LCK_WAIT);
|
LCK_lock(tdbb, lock, LCK_PW, LCK_WAIT);
|
||||||
|
|
||||||
|
counter->isProtected = true;
|
||||||
counter->curVal = 1;
|
counter->curVal = 1;
|
||||||
counter->maxVal = 0;
|
counter->maxVal = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter->curVal > counter->maxVal)
|
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);
|
counter->curVal = LCK_read_data(tdbb, counter->lock);
|
||||||
|
|
||||||
@ -196,6 +201,7 @@ namespace Jrd
|
|||||||
Jrd::ContextPoolHolder context(tdbb, dbb->dbb_permanent);
|
Jrd::ContextPoolHolder context(tdbb, dbb->dbb_permanent);
|
||||||
|
|
||||||
LCK_downgrade(tdbb, counter->lock);
|
LCK_downgrade(tdbb, counter->lock);
|
||||||
|
counter->isProtected = false;
|
||||||
}
|
}
|
||||||
catch (const Firebird::Exception&)
|
catch (const Firebird::Exception&)
|
||||||
{} // no-op
|
{} // no-op
|
||||||
|
@ -287,6 +287,7 @@ public:
|
|||||||
struct ValueCache
|
struct ValueCache
|
||||||
{
|
{
|
||||||
Lock* lock;
|
Lock* lock;
|
||||||
|
bool isProtected;
|
||||||
SLONG curVal;
|
SLONG curVal;
|
||||||
SLONG maxVal;
|
SLONG maxVal;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user