| 828 | |
| 829 | |
| 830 | LockState CCH_fetch_lock(thread_db* tdbb, WIN* window, int lock_type, int wait, SCHAR page_type) |
| 831 | { |
| 832 | /************************************** |
| 833 | * |
| 834 | * C C H _ f e t c h _ l o c k |
| 835 | * |
| 836 | ************************************** |
| 837 | * |
| 838 | * Functional description |
| 839 | * Fetch a latch and lock for a specific page. |
| 840 | * |
| 841 | * input |
| 842 | * |
| 843 | * wait: |
| 844 | * LCK_WAIT (1) => Wait as long a necessary to get the lock. |
| 845 | * This can cause deadlocks of course. |
| 846 | * |
| 847 | * LCK_NO_WAIT (0) => |
| 848 | * If the latch can't be acquired immediately, give up and return -2. |
| 849 | * If the lock can't be acquired immediately, give up and return -1. |
| 850 | * |
| 851 | * <negative number> => Lock (latch) timeout interval in seconds. |
| 852 | * |
| 853 | * return |
| 854 | * 0: fetch & lock were successful, page doesn't need to be read. |
| 855 | * 1: fetch & lock were successful, page needs to be read from disk. |
| 856 | * -1: lock timed out, fetch failed. |
| 857 | * -2: latch timed out, fetch failed, lock not attempted. |
| 858 | * |
| 859 | **************************************/ |
| 860 | SET_TDBB(tdbb); |
| 861 | Database* const dbb = tdbb->getDatabase(); |
| 862 | BufferControl* const bcb = dbb->dbb_bcb; |
| 863 | |
| 864 | // if there has been a shadow added recently, go out and |
| 865 | // find it before we grant any more write locks |
| 866 | |
| 867 | if (dbb->dbb_ast_flags & DBB_get_shadows) |
| 868 | SDW_get_shadows(tdbb); |
| 869 | |
| 870 | // Look for the page in the cache. |
| 871 | |
| 872 | BufferDesc* bdb = get_buffer(tdbb, window->win_page, |
| 873 | ((lock_type >= LCK_write) ? SYNC_EXCLUSIVE : SYNC_SHARED), wait); |
| 874 | |
| 875 | if (wait != 1 && bdb == 0) |
| 876 | return lsLatchTimeout; // latch timeout |
| 877 | |
| 878 | fb_assert(bdb->bdb_page == window->win_page); |
| 879 | if (!(bdb->bdb_flags & BDB_read_pending)) |
| 880 | fb_assert(bdb->bdb_buffer->pag_pageno == window->win_page.getPageNum()); |
| 881 | else |
| 882 | fb_assert(bdb->ourExclusiveLock() || bdb->bdb_lock && bdb->bdb_lock->lck_logical == LCK_none); |
| 883 | |
| 884 | if (lock_type >= LCK_write) |
| 885 | bdb->bdb_flags |= BDB_writer; |
| 886 | |
| 887 | window->win_bdb = bdb; |
no test coverage detected