From 8f742ba52cabaa3c30856e437456f5df9061ed75 Mon Sep 17 00:00:00 2001 From: dimitr Date: Sat, 26 Jan 2008 12:57:52 +0000 Subject: [PATCH] Major synchronization changes. Description of the commit will be posted to fb-devel. --- src/jrd/dfw.epp | 67 ++++++++++++++++++++++------------------------- src/jrd/dyn.epp | 12 +++------ src/jrd/event.cpp | 4 --- src/jrd/evl.cpp | 2 +- src/jrd/exe.cpp | 2 +- 5 files changed, 38 insertions(+), 49 deletions(-) diff --git a/src/jrd/dfw.epp b/src/jrd/dfw.epp index 1fd09c0b54..6c568058b3 100644 --- a/src/jrd/dfw.epp +++ b/src/jrd/dfw.epp @@ -1957,18 +1957,15 @@ static bool create_index( thread_db* tdbb, if (partner_relation) { + // signal to other processes about new constraint + LCK_convert(tdbb, relation->rel_partners_lock, LCK_EX, LCK_WAIT); + LCK_release(tdbb, relation->rel_partners_lock); relation->rel_flags |= REL_check_partners; - // signal to other processes about new constraint - LCK_convert_non_blocking(tdbb, relation->rel_partners_lock, - LCK_EX, LCK_WAIT); - LCK_release(tdbb, relation->rel_partners_lock); - if (relation != partner_relation) { - partner_relation->rel_flags |= REL_check_partners; - LCK_convert_non_blocking(tdbb, partner_relation->rel_partners_lock, - LCK_EX, LCK_WAIT); + LCK_convert(tdbb, partner_relation->rel_partners_lock, LCK_EX, LCK_WAIT); LCK_release(tdbb, partner_relation->rel_partners_lock); + partner_relation->rel_flags |= REL_check_partners; } } if (relationLock && releaseRelationLock) { @@ -2103,7 +2100,7 @@ static bool create_relation(thread_db* tdbb, lock->lck_owner_handle = LCK_get_owner_handle(tdbb, lock->lck_type); lock->lck_parent = dbb->dbb_lock; - LCK_lock_non_blocking(tdbb, lock, LCK_EX, LCK_WAIT); + LCK_lock(tdbb, lock, LCK_EX, LCK_WAIT); /* Assign a relation ID and dbkey length to the new relation. Probe the candidate relation ID returned from the system @@ -2896,7 +2893,10 @@ static void check_partners(thread_db* tdbb, const USHORT rel_id) jrd_rel *relation = (*relations)[rel_id]; fb_assert(relation); - LCK_lock_non_blocking(tdbb, relation->rel_partners_lock, LCK_EX, LCK_WAIT); + if (relation->rel_flags & REL_check_partners) + LCK_lock(tdbb, relation->rel_partners_lock, LCK_EX, LCK_WAIT); + else + LCK_convert(tdbb, relation->rel_partners_lock, LCK_EX, LCK_WAIT); LCK_release(tdbb, relation->rel_partners_lock); relation->rel_flags |= REL_check_partners; } @@ -2990,13 +2990,13 @@ static bool delete_index(thread_db* tdbb, SSHORT phase, DeferredWork* work, if (!isTempIndex) { if (index->idl_count || - !LCK_lock_non_blocking(tdbb, index->idl_lock, LCK_EX, - transaction->getLockWait())) + !LCK_lock(tdbb, index->idl_lock, LCK_EX, + transaction->getLockWait())) { // restore lock used by temp index instance if (temp_lock_released) { - LCK_lock_non_blocking(tdbb, index->idl_lock, LCK_SR, LCK_WAIT); + LCK_lock(tdbb, index->idl_lock, LCK_SR, LCK_WAIT); index->idl_count++; } @@ -3184,8 +3184,8 @@ static bool delete_procedure( thread_db* tdbb, if (procedure->prc_existence_lock) { - LCK_convert_non_blocking(tdbb, procedure->prc_existence_lock, - LCK_SR, transaction->getLockWait()); + LCK_convert(tdbb, procedure->prc_existence_lock, LCK_SR, + transaction->getLockWait()); } return false; @@ -3202,8 +3202,8 @@ static bool delete_procedure( thread_db* tdbb, if (procedure->prc_existence_lock) { - if (!LCK_convert_non_blocking(tdbb, procedure->prc_existence_lock, - LCK_EX, transaction->getLockWait())) + if (!LCK_convert(tdbb, procedure->prc_existence_lock, LCK_EX, + transaction->getLockWait())) { ERR_post(isc_no_meta_update, isc_arg_gds, isc_obj_in_use, @@ -3311,8 +3311,8 @@ static bool delete_relation(thread_db* tdbb, SSHORT phase, DeferredWork* work, if (relation->rel_existence_lock) { - LCK_convert_non_blocking(tdbb, relation->rel_existence_lock, - LCK_SR, transaction->getLockWait()); + LCK_convert(tdbb, relation->rel_existence_lock, LCK_SR, + transaction->getLockWait()); } relation->rel_flags &= ~REL_deleting; @@ -3376,8 +3376,8 @@ static bool delete_relation(thread_db* tdbb, SSHORT phase, DeferredWork* work, MET_clear_cache(tdbb); if (relation->rel_use_count || (relation->rel_existence_lock && - !LCK_convert_non_blocking(tdbb, relation->rel_existence_lock, - LCK_EX, transaction->getLockWait()))) + !LCK_convert(tdbb, relation->rel_existence_lock, LCK_EX, + transaction->getLockWait()))) { if (adjusted) { ++relation->rel_use_count; @@ -3415,9 +3415,8 @@ static bool delete_relation(thread_db* tdbb, SSHORT phase, DeferredWork* work, break; } - THREAD_EXIT(); + Database::Checkout dcoHolder(dbb); THREAD_SLEEP(1 * 1000); - THREAD_ENTER(); } if (relation->rel_sweep_count) @@ -4629,8 +4628,8 @@ static bool modify_procedure( thread_db* tdbb, if (procedure->prc_existence_lock) { - LCK_convert_non_blocking(tdbb, procedure->prc_existence_lock, - LCK_SR, transaction->getLockWait()); + LCK_convert(tdbb, procedure->prc_existence_lock, LCK_SR, + transaction->getLockWait()); } return false; } @@ -4650,8 +4649,8 @@ static bool modify_procedure( thread_db* tdbb, { /* Let procedure be deleted if only this transaction is using it */ - if (!LCK_convert_non_blocking(tdbb, procedure->prc_existence_lock, - LCK_EX, transaction->getLockWait())) + if (!LCK_convert(tdbb, procedure->prc_existence_lock, LCK_EX, + transaction->getLockWait())) { ERR_post(isc_no_meta_update, isc_arg_gds, isc_obj_in_use, @@ -4674,13 +4673,11 @@ static bool modify_procedure( thread_db* tdbb, try { - THREAD_EXIT(); - if (tdbb->getDatabase()->dbb_sp_rec_mutex.enter()) - { - THREAD_ENTER(); - return false; + { // scope + Database::Checkout dcoHolder(dbb); + if (tdbb->getDatabase()->dbb_sp_rec_mutex.enter()) + return false; } - THREAD_ENTER(); // Do not allow to modify procedure used by user requests if (procedure->prc_use_count && MET_procedure_in_use(tdbb, procedure)) @@ -5134,13 +5131,13 @@ static Lock* protect_relation(thread_db* tdbb, jrd_tra* transaction, jrd_rel* re if (!releaseLock) { if ( (relLock->lck_logical < LCK_PR) && - !LCK_convert_non_blocking(tdbb, relLock, LCK_PR, transaction->getLockWait()) ) + !LCK_convert(tdbb, relLock, LCK_PR, transaction->getLockWait()) ) { inUse = true; } } else { - if ( !LCK_lock_non_blocking(tdbb, relLock, LCK_PR, transaction->getLockWait()) ) { + if (!LCK_lock(tdbb, relLock, LCK_PR, transaction->getLockWait())) { inUse = true; } } diff --git a/src/jrd/dyn.epp b/src/jrd/dyn.epp index 435179fc99..c52d0223a2 100644 --- a/src/jrd/dyn.epp +++ b/src/jrd/dyn.epp @@ -2208,6 +2208,8 @@ static void dyn_user(Global* gbl, const UCHAR** ptr) char securityDatabaseName[MAXPATHLEN]; SecurityDatabase::getPath(securityDatabaseName); + Database::Checkout dcoHolder(dbb); + Firebird::ClumpletWriter dpb(Firebird::ClumpletReader::Tagged, MAX_DPB_SIZE, isc_dpb_version1); dpb.insertByte(isc_dpb_gsec_attach, TRUE); dpb.insertString(isc_dpb_trusted_auth, tdbb->getAttachment()->att_user->usr_user_name); @@ -2216,10 +2218,9 @@ static void dyn_user(Global* gbl, const UCHAR** ptr) ISC_STATUS_ARRAY status; try { - THREAD_EXIT(); isc_attach_database(status, 0, securityDatabaseName, &securityDatabase, dpb.getBufferLength(), reinterpret_cast(dpb.getBuffer())); - THREAD_ENTER(); + if (status[1]) { Firebird::status_exception::raise(status); @@ -2303,10 +2304,8 @@ static void dyn_user(Global* gbl, const UCHAR** ptr) } } - THREAD_EXIT(); int errcode = (! userData.user_name_entered) ? GsecMsg18 : SECURITY_exec_line(status, securityDatabase, &userData, NULL, NULL); - THREAD_ENTER(); switch (errcode) { @@ -2319,9 +2318,8 @@ static void dyn_user(Global* gbl, const UCHAR** ptr) Firebird::status_exception::raise(ENCODE_ISC_MSG(errcode, GSEC_MSG_FAC), isc_arg_end); } - THREAD_EXIT(); isc_detach_database(status, &securityDatabase); - THREAD_ENTER(); + if (status[1]) { securityDatabase = 0; @@ -2332,9 +2330,7 @@ static void dyn_user(Global* gbl, const UCHAR** ptr) { if (securityDatabase) { - THREAD_EXIT(); isc_detach_database(status, &securityDatabase); - THREAD_ENTER(); } e.stuff_exception(status); memmove(&status[2], &status[0], sizeof(status) - 2 * sizeof(status[0])); diff --git a/src/jrd/event.cpp b/src/jrd/event.cpp index bd31f82a6e..f15da08263 100644 --- a/src/jrd/event.cpp +++ b/src/jrd/event.cpp @@ -574,9 +574,7 @@ static FRB alloc_global(UCHAR type, ULONG length, bool recurse) while (true) { release(); - THREAD_EXIT(); Sleep(3); - THREAD_ENTER(); acquire(); process = (PRB) SRQ_ABS_PTR(EVENT_process_offset); @@ -816,9 +814,7 @@ static void delete_session(SLONG session_id) // give a chance for delivering thread to detect SES_purge flag we just set release(); - THREAD_EXIT(); THREAD_SLEEP(100); - THREAD_ENTER(); acquire(); return; diff --git a/src/jrd/evl.cpp b/src/jrd/evl.cpp index d764568c0a..ac930c4223 100644 --- a/src/jrd/evl.cpp +++ b/src/jrd/evl.cpp @@ -912,7 +912,7 @@ dsc* EVL_expr(thread_db* tdbb, jrd_nod* const node) } case nod_function: - FUN_evaluate(reinterpret_cast(node->nod_arg[e_fun_function]), + FUN_evaluate(tdbb, reinterpret_cast(node->nod_arg[e_fun_function]), node->nod_arg[e_fun_args], impure); return &impure->vlu_desc; diff --git a/src/jrd/exe.cpp b/src/jrd/exe.cpp index b68c1290ad..64305fbe7d 100644 --- a/src/jrd/exe.cpp +++ b/src/jrd/exe.cpp @@ -1036,7 +1036,7 @@ void EXE_start(thread_db* tdbb, jrd_req* request, jrd_tra* transaction) Lock* lock = transaction->tra_cancel_lock; if (lock && lock->lck_logical == LCK_none) - LCK_lock_non_blocking(tdbb, lock, LCK_SR, LCK_WAIT); + LCK_lock(tdbb, lock, LCK_SR, LCK_WAIT); TRA_attach_request(transaction, request); request->req_flags &= REQ_FLAGS_INIT_MASK;