MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / CCH_exclusive

Function CCH_exclusive

src/jrd/cch.cpp:469–530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

467
468
469bool CCH_exclusive(thread_db* tdbb, USHORT level, SSHORT wait_flag, Firebird::Sync* guard)
470{
471/**************************************
472 *
473 * C C H _ e x c l u s i v e
474 *
475 **************************************
476 *
477 * Functional description
478 * Get exclusive access to a database. If we get it, return true.
479 * If the wait flag is FALSE, and we can't get it, give up and
480 * return false. There are two levels of database exclusivity: LCK_PW
481 * guarantees there are no normal users in the database while LCK_EX
482 * additionally guarantees background database processes like the
483 * shared cache manager have detached.
484 *
485 **************************************/
486 SET_TDBB(tdbb);
487 Database* dbb = tdbb->getDatabase();
488
489 if (dbb->dbb_flags & DBB_shared)
490 {
491 if (!CCH_exclusive_attachment(tdbb, level, wait_flag, guard))
492 return false;
493 }
494
495 Lock* lock = dbb->dbb_lock;
496 if (!lock)
497 return false;
498
499 dbb->dbb_flags |= DBB_exclusive;
500
501 switch (level)
502 {
503 case LCK_PW:
504 if (lock->lck_physical >= LCK_PW || LCK_convert(tdbb, lock, LCK_PW, wait_flag))
505 return true;
506 break;
507
508 case LCK_EX:
509 if (lock->lck_physical == LCK_EX || LCK_convert(tdbb, lock, LCK_EX, wait_flag))
510 return true;
511 break;
512
513 default:
514 break;
515 }
516
517 // Clear the status vector, as our callers check the return value
518 // and throw custom exceptions themselves
519 fb_utils::init_status(tdbb->tdbb_status_vector);
520
521 // If we are supposed to wait (presumably patiently),
522 // but can't get the lock, generate an error
523
524 if (wait_flag == LCK_WAIT)
525 ERR_post(Arg::Gds(isc_deadlock));
526

Callers 5

internalAttachMethod · 0.85
createDatabaseMethod · 0.85
internalDropDatabaseMethod · 0.85
SHUT_databaseFunction · 0.85
notify_shutdownFunction · 0.85

Calls 7

SET_TDBBFunction · 0.85
CCH_exclusive_attachmentFunction · 0.85
LCK_convertFunction · 0.85
init_statusFunction · 0.85
GdsClass · 0.85
getDatabaseMethod · 0.80
ERR_postFunction · 0.70

Tested by

no test coverage detected