mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 22:43: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
a76dd8d3e7
commit
46cc7d15af
@ -156,13 +156,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)
|
||||
{
|
||||
if (!counter->isProtected)
|
||||
{
|
||||
LCK_convert(tdbb, counter->lock, LCK_PW, LCK_WAIT);
|
||||
counter->isProtected = true;
|
||||
}
|
||||
|
||||
counter->curVal = LCK_read_data(tdbb, counter->lock);
|
||||
|
||||
@ -192,6 +197,7 @@ namespace Jrd
|
||||
SyncLockGuard guard(&dbb->dbb_sh_counter_sync, SYNC_EXCLUSIVE, "Database::blockingAstSharedCounter");
|
||||
|
||||
LCK_downgrade(tdbb, counter->lock);
|
||||
counter->isProtected = false;
|
||||
}
|
||||
catch (const Exception&)
|
||||
{} // no-op
|
||||
|
@ -237,6 +237,7 @@ public:
|
||||
struct ValueCache
|
||||
{
|
||||
Lock* lock; // lock which holds shared counter value
|
||||
bool isProtected; // flag indicating that we own the lock in the PW mode
|
||||
SLONG curVal; // current value of shared counter lock
|
||||
SLONG maxVal; // maximum cached value of shared counter lock
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user