| 1431 | |
| 1432 | |
| 1433 | pag* CCH_handoff(thread_db* tdbb, WIN* window, ULONG page, int lock, SCHAR page_type, |
| 1434 | int wait, const bool release_tail) |
| 1435 | { |
| 1436 | /************************************** |
| 1437 | * |
| 1438 | * C C H _ h a n d o f f |
| 1439 | * |
| 1440 | ************************************** |
| 1441 | * |
| 1442 | * Functional description |
| 1443 | * Follow a pointer handing off the lock. Fetch the new page |
| 1444 | * before retiring the old page lock. |
| 1445 | * |
| 1446 | * input |
| 1447 | * wait: 1 => Wait as long as necessary to get the latch. |
| 1448 | * This can cause deadlocks of course. |
| 1449 | * 0 => If the latch can't be acquired immediately, |
| 1450 | * give up and return 0. |
| 1451 | * <negative number> => Latch timeout interval in seconds. |
| 1452 | * |
| 1453 | * return |
| 1454 | * PAG if successful. |
| 1455 | * 0 if a latch timeout occurred (only possible if wait <> 1). |
| 1456 | * The latch on the fetched page is downgraded to shared. |
| 1457 | * The fetched page is unmarked. |
| 1458 | * |
| 1459 | **************************************/ |
| 1460 | |
| 1461 | // The update, if there was one, of the input page is complete. |
| 1462 | // The cache buffer can be 'unmarked'. It is important to |
| 1463 | // unmark before CCH_unwind is (might be) called. |
| 1464 | |
| 1465 | SET_TDBB(tdbb); |
| 1466 | |
| 1467 | CCH_TRACE(("HANDOFF %d:%06d->%06d, %s", |
| 1468 | window->win_page.getPageSpaceID(), window->win_page.getPageNum(), page, (lock >= LCK_write) ? "EX" : "SH")); |
| 1469 | |
| 1470 | BufferDesc *bdb = window->win_bdb; |
| 1471 | |
| 1472 | // unmark |
| 1473 | if (bdb->bdb_writers == 1 && (bdb->bdb_flags & BDB_marked)) |
| 1474 | { |
| 1475 | bdb->bdb_flags &= ~BDB_marked; |
| 1476 | bdb->unLockIO(tdbb); |
| 1477 | } |
| 1478 | |
| 1479 | // If the 'from-page' and 'to-page' of the handoff are the |
| 1480 | // same and the latch requested is shared then downgrade it. |
| 1481 | |
| 1482 | if ((window->win_page.getPageNum() == page) && (lock == LCK_read)) |
| 1483 | { |
| 1484 | if (bdb->ourExclusiveLock()) |
| 1485 | bdb->downgrade(SYNC_SHARED); |
| 1486 | |
| 1487 | return window->win_buffer; |
| 1488 | } |
| 1489 | |
| 1490 | WIN temp = *window; |
no test coverage detected