| 3776 | |
| 3777 | |
| 3778 | static BufferDesc* get_buffer(thread_db* tdbb, const PageNumber page, SyncType syncType, int wait) |
| 3779 | { |
| 3780 | /************************************** |
| 3781 | * |
| 3782 | * g e t _ b u f f e r |
| 3783 | * |
| 3784 | ************************************** |
| 3785 | * |
| 3786 | * Functional description |
| 3787 | * Get a buffer. If possible, get a buffer already assigned |
| 3788 | * to the page. Otherwise get one from the free list or pick |
| 3789 | * the least recently used buffer to be reused. |
| 3790 | * |
| 3791 | * input |
| 3792 | * page: page to get |
| 3793 | * syncType: type of lock to acquire on the page. |
| 3794 | * wait: 1 => Wait as long as necessary to get the lock. |
| 3795 | * This can cause deadlocks of course. |
| 3796 | * 0 => If the lock can't be acquired immediately, |
| 3797 | * give up and return 0; |
| 3798 | * <negative number> => Latch timeout interval in seconds. |
| 3799 | * |
| 3800 | * return |
| 3801 | * BufferDesc pointer if successful. |
| 3802 | * NULL pointer if timeout occurred (only possible is wait <> 1). |
| 3803 | * if cache manager doesn't have any pages to write anymore. |
| 3804 | * |
| 3805 | **************************************/ |
| 3806 | SET_TDBB(tdbb); |
| 3807 | Database* dbb = tdbb->getDatabase(); |
| 3808 | BufferControl* bcb = dbb->dbb_bcb; |
| 3809 | Attachment* att = tdbb->getAttachment(); |
| 3810 | |
| 3811 | if (att && att->att_bdb_cache) |
| 3812 | { |
| 3813 | if (BufferDesc* bdb = att->att_bdb_cache->get(page)) |
| 3814 | { |
| 3815 | if (bdb->addRef(tdbb, syncType, wait)) |
| 3816 | { |
| 3817 | if (bdb->bdb_page == page) |
| 3818 | { |
| 3819 | recentlyUsed(bdb); |
| 3820 | tdbb->bumpStats(RuntimeStatistics::PAGE_FETCHES); |
| 3821 | return bdb; |
| 3822 | } |
| 3823 | |
| 3824 | bdb->release(tdbb, true); |
| 3825 | att->att_bdb_cache->remove(page); |
| 3826 | } |
| 3827 | else |
| 3828 | { |
| 3829 | fb_assert(wait <= 0); |
| 3830 | if (bdb->bdb_page == page) |
| 3831 | return nullptr; |
| 3832 | } |
| 3833 | } |
| 3834 | } |
| 3835 |
no test coverage detected