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

Backport from master:

Remove not necessary sync points - dbb_threads_sync and dbb_lck_sync
This commit is contained in:
hvlad 2016-12-30 01:50:49 +02:00
parent ef980a2015
commit 8ca97fb718
6 changed files with 38 additions and 99 deletions

View File

@ -601,9 +601,6 @@ void Jrd::Attachment::detachLocks()
if (!att_long_locks) if (!att_long_locks)
return; return;
Sync lckSync(&att_database->dbb_lck_sync, "Attachment::detachLocks");
lckSync.lock(SYNC_EXCLUSIVE);
Lock* long_lock = att_long_locks; Lock* long_lock = att_long_locks;
while (long_lock) while (long_lock)
long_lock = long_lock->detach(); long_lock = long_lock->detach();

View File

@ -96,14 +96,6 @@ namespace Jrd
delete dbb_monitoring_data; delete dbb_monitoring_data;
delete dbb_backup_manager; delete dbb_backup_manager;
delete dbb_crypto_manager; delete dbb_crypto_manager;
while (dbb_active_threads)
{
thread_db* tdbb = dbb_active_threads;
tdbb->deactivate();
tdbb->setDatabase(NULL);
}
delete dbb_tip_cache; delete dbb_tip_cache;
fb_assert(!locked()); fb_assert(!locked());

View File

@ -370,7 +370,6 @@ public:
Firebird::SyncObject dbb_sync; Firebird::SyncObject dbb_sync;
Firebird::SyncObject dbb_sys_attach; // synchronize operations with dbb_sys_attachments Firebird::SyncObject dbb_sys_attach; // synchronize operations with dbb_sys_attachments
Firebird::SyncObject dbb_lck_sync; // synchronize operations with att_long_locks at different attachments
MemoryPool* dbb_permanent; MemoryPool* dbb_permanent;
@ -431,9 +430,6 @@ public:
Firebird::SyncObject dbb_sortbuf_sync; Firebird::SyncObject dbb_sortbuf_sync;
Firebird::Array<UCHAR*> dbb_sort_buffers; // sort buffers ready for reuse Firebird::Array<UCHAR*> dbb_sort_buffers; // sort buffers ready for reuse
Firebird::SyncObject dbb_threads_sync;
thread_db* dbb_active_threads;
TraNumber dbb_oldest_active; // Cached "oldest active" transaction TraNumber dbb_oldest_active; // Cached "oldest active" transaction
TraNumber dbb_oldest_transaction; // Cached "oldest interesting" transaction TraNumber dbb_oldest_transaction; // Cached "oldest interesting" transaction
TraNumber dbb_oldest_snapshot; // Cached "oldest snapshot" of all active transactions TraNumber dbb_oldest_snapshot; // Cached "oldest snapshot" of all active transactions

View File

@ -7447,16 +7447,8 @@ void thread_db::setDatabase(Database* val)
{ {
if (database != val) if (database != val)
{ {
const bool wasActive = database && (priorThread || nextThread || database->dbb_active_threads == this);
if (wasActive)
deactivate();
database = val; database = val;
dbbStat = val ? &val->dbb_stats : RuntimeStatistics::getDummy(); dbbStat = val ? &val->dbb_stats : RuntimeStatistics::getDummy();
if (wasActive)
activate();
} }
} }

View File

@ -381,7 +381,6 @@ private:
jrd_tra* transaction; jrd_tra* transaction;
jrd_req* request; jrd_req* request;
RuntimeStatistics *reqStat, *traStat, *attStat, *dbbStat; RuntimeStatistics *reqStat, *traStat, *attStat, *dbbStat;
thread_db *priorThread, *nextThread;
public: public:
explicit thread_db(FbStatusVector* status) explicit thread_db(FbStatusVector* status)
@ -391,8 +390,6 @@ public:
attachment(NULL), attachment(NULL),
transaction(NULL), transaction(NULL),
request(NULL), request(NULL),
priorThread(NULL),
nextThread(NULL),
tdbb_status_vector(status), tdbb_status_vector(status),
tdbb_quantum(QUANTUM), tdbb_quantum(QUANTUM),
tdbb_flags(0), tdbb_flags(0),
@ -578,54 +575,6 @@ public:
return true; return true;
} }
void activate()
{
fb_assert(!priorThread && !nextThread);
if (database)
{
Firebird::SyncLockGuard sync(&database->dbb_threads_sync, Firebird::SYNC_EXCLUSIVE,
"thread_db::activate");
if (database->dbb_active_threads)
{
fb_assert(!database->dbb_active_threads->priorThread);
database->dbb_active_threads->priorThread = this;
nextThread = database->dbb_active_threads;
}
database->dbb_active_threads = this;
}
}
void deactivate()
{
if (database)
{
Firebird::SyncLockGuard sync(&database->dbb_threads_sync, Firebird::SYNC_EXCLUSIVE,
"thread_db::deactivate");
if (nextThread)
{
fb_assert(nextThread->priorThread == this);
nextThread->priorThread = priorThread;
}
if (priorThread)
{
fb_assert(priorThread->nextThread == this);
priorThread->nextThread = nextThread;
}
else
{
fb_assert(database->dbb_active_threads == this);
database->dbb_active_threads = nextThread;
}
}
priorThread = nextThread = NULL;
}
void resetStack() void resetStack()
{ {
if (tdbb_flags & TDBB_reset_stack) if (tdbb_flags & TDBB_reset_stack)
@ -860,23 +809,13 @@ namespace Jrd {
{ {
public: public:
explicit DatabaseContextHolder(thread_db* tdbb) explicit DatabaseContextHolder(thread_db* tdbb)
: Jrd::ContextPoolHolder(tdbb, tdbb->getDatabase()->dbb_permanent), : Jrd::ContextPoolHolder(tdbb, tdbb->getDatabase()->dbb_permanent)
savedTdbb(tdbb) {}
{
savedTdbb->activate();
}
~DatabaseContextHolder()
{
savedTdbb->deactivate();
}
private: private:
// copying is prohibited // copying is prohibited
DatabaseContextHolder(const DatabaseContextHolder&); DatabaseContextHolder(const DatabaseContextHolder&);
DatabaseContextHolder& operator=(const DatabaseContextHolder&); DatabaseContextHolder& operator=(const DatabaseContextHolder&);
thread_db* const savedTdbb;
}; };
class BackgroundContextHolder : public ThreadContextHolder, public DatabaseContextHolder, class BackgroundContextHolder : public ThreadContextHolder, public DatabaseContextHolder,

View File

@ -70,6 +70,7 @@ static void internal_dequeue(thread_db*, Lock*);
static USHORT internal_downgrade(thread_db*, CheckStatusWrapper*, Lock*); static USHORT internal_downgrade(thread_db*, CheckStatusWrapper*, Lock*);
static bool internal_enqueue(thread_db*, CheckStatusWrapper*, Lock*, USHORT, SSHORT, bool); static bool internal_enqueue(thread_db*, CheckStatusWrapper*, Lock*, USHORT, SSHORT, bool);
static SLONG get_owner_handle(thread_db* tdbb, enum lck_t lock_type); static SLONG get_owner_handle(thread_db* tdbb, enum lck_t lock_type);
static lck_owner_t get_owner_type(enum lck_t lock_type);
#ifdef DEBUG_LCK #ifdef DEBUG_LCK
namespace namespace
@ -508,6 +509,33 @@ static SLONG get_owner_handle(thread_db* tdbb, enum lck_t lock_type)
SLONG handle = 0; SLONG handle = 0;
switch (get_owner_type(lock_type))
{
case LCK_OWNER_database:
handle = *LCK_OWNER_HANDLE_DBB(tdbb);
break;
case LCK_OWNER_attachment:
handle = *LCK_OWNER_HANDLE_ATT(tdbb);
break;
default:
bug_lck("Invalid lock owner type in get_owner_handle()");
}
if (!handle)
{
bug_lck("Invalid lock owner handle");
}
return handle;
}
static lck_owner_t get_owner_type(enum lck_t lock_type)
{
lck_owner_t owner_type;
switch (lock_type) switch (lock_type)
{ {
case LCK_database: case LCK_database:
@ -519,7 +547,7 @@ static SLONG get_owner_handle(thread_db* tdbb, enum lck_t lock_type)
case LCK_sweep: case LCK_sweep:
case LCK_crypt: case LCK_crypt:
case LCK_crypt_status: case LCK_crypt_status:
handle = *LCK_OWNER_HANDLE_DBB(tdbb); owner_type = LCK_OWNER_database;
break; break;
case LCK_attachment: case LCK_attachment:
@ -543,19 +571,14 @@ static SLONG get_owner_handle(thread_db* tdbb, enum lck_t lock_type)
case LCK_btr_dont_gc: case LCK_btr_dont_gc:
case LCK_rel_gc: case LCK_rel_gc:
case LCK_record_gc: case LCK_record_gc:
handle = *LCK_OWNER_HANDLE_ATT(tdbb); owner_type = LCK_OWNER_attachment;
break; break;
default: default:
bug_lck("Invalid lock type in get_owner_handle()"); bug_lck("Invalid lock type in get_owner_type()");
} }
if (!handle) return owner_type;
{
bug_lck("Invalid lock owner handle");
}
return handle;
} }
@ -1473,20 +1496,20 @@ Lock::Lock(thread_db* tdbb, USHORT length, lck_t type, void* object, lock_ast_t
void Lock::setLockAttachment(thread_db* tdbb, Jrd::Attachment* attachment) void Lock::setLockAttachment(thread_db* tdbb, Jrd::Attachment* attachment)
{ {
if (get_owner_type(lck_type) == LCK_OWNER_database)
return;
SET_TDBB(tdbb); SET_TDBB(tdbb);
Database* dbb = tdbb->getDatabase(); Database* dbb = tdbb->getDatabase();
fb_assert(dbb); fb_assert(dbb);
if (!dbb) if (!dbb)
return; return;
Sync lckSync(&dbb->dbb_lck_sync, "setLockAttachment");
lckSync.lock(SYNC_EXCLUSIVE);
Attachment* att = lck_attachment ? lck_attachment->getHandle() : NULL; Attachment* att = lck_attachment ? lck_attachment->getHandle() : NULL;
if (att == attachment) if (att == attachment)
return; return;
// If lock has an attachment it must not be a part of linked list // If lock has no attachment it must not be a part of linked list
fb_assert(!lck_attachment ? !lck_prior && !lck_next : true); fb_assert(!lck_attachment ? !lck_prior && !lck_next : true);
// Delist in old attachment // Delist in old attachment