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

Function get_oldest_buffer

src/jrd/cch.cpp:3667–3775  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3665
3666
3667static BufferDesc* get_oldest_buffer(thread_db* tdbb, BufferControl* bcb)
3668{
3669/**************************************
3670 * Function description:
3671 * Get candidate for preemption
3672 * Found page buffer must have SYNC_EXCLUSIVE lock.
3673 **************************************/
3674
3675 int walk = bcb->bcb_free_minimum;
3676 BufferDesc* bdb = nullptr;
3677
3678 Sync lruSync(&bcb->bcb_syncLRU, FB_FUNCTION);
3679 if (bcb->bcb_lru_chain.load() != NULL)
3680 {
3681 lruSync.lock(SYNC_EXCLUSIVE);
3682 requeueRecentlyUsed(bcb);
3683 lruSync.downgrade(SYNC_SHARED);
3684 }
3685 else
3686 lruSync.lock(SYNC_SHARED);
3687
3688 for (QUE que_inst = bcb->bcb_in_use.que_backward;
3689 que_inst != &bcb->bcb_in_use;
3690 que_inst = que_inst->que_backward)
3691 {
3692 bdb = nullptr;
3693
3694 // get the oldest buffer as the least recently used -- note
3695 // that since there are no empty buffers this queue cannot be empty
3696
3697 if (bcb->bcb_in_use.que_forward == &bcb->bcb_in_use)
3698 BUGCHECK(213); // msg 213 insufficient cache size
3699
3700 BufferDesc* oldest = BLOCK(que_inst, BufferDesc, bdb_in_use);
3701
3702 if (oldest->bdb_flags & BDB_lru_chained)
3703 continue;
3704
3705 if (oldest->bdb_use_count || !oldest->addRefConditional(tdbb, SYNC_EXCLUSIVE))
3706 continue;
3707
3708 /*if (!writeable(oldest))
3709 {
3710 oldest->release(tdbb, true);
3711 continue;
3712 }*/
3713
3714 bdb = oldest;
3715 if (!(bdb->bdb_flags & (BDB_dirty | BDB_db_dirty)) || !walk)
3716 break;
3717
3718 if (!(bcb->bcb_flags & BCB_cache_writer))
3719 break;
3720
3721 bcb->bcb_flags |= BCB_free_pending;
3722 if (!(bcb->bcb_flags & BCB_writer_active))
3723 bcb->bcb_writer_sem.release();
3724

Callers 1

get_bufferFunction · 0.85

Calls 13

requeueRecentlyUsedFunction · 0.85
write_bufferFunction · 0.85
CCH_unwindFunction · 0.85
removeDirtyFunction · 0.85
QUE_NOT_EMPTYFunction · 0.85
QUE_DELETEFunction · 0.85
clear_precedenceFunction · 0.85
addRefConditionalMethod · 0.80
loadMethod · 0.45
lockMethod · 0.45
downgradeMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected