| 1544 | |
| 1545 | |
| 1546 | void CCH_init(thread_db* tdbb, ULONG number) |
| 1547 | { |
| 1548 | /************************************** |
| 1549 | * |
| 1550 | * C C H _ i n i t |
| 1551 | * |
| 1552 | ************************************** |
| 1553 | * |
| 1554 | * Functional description |
| 1555 | * Initialize the cache. Allocate buffers control block, |
| 1556 | * buffer descriptors, and actual buffers. |
| 1557 | * |
| 1558 | **************************************/ |
| 1559 | SET_TDBB(tdbb); |
| 1560 | Database* const dbb = tdbb->getDatabase(); |
| 1561 | const bool shared = (dbb->dbb_flags & DBB_shared); |
| 1562 | |
| 1563 | CCH_TRACE(("INIT %s", dbb->dbb_filename.c_str())); |
| 1564 | |
| 1565 | // Check for database-specific page buffers |
| 1566 | |
| 1567 | if (dbb->dbb_page_buffers) |
| 1568 | number = dbb->dbb_page_buffers; |
| 1569 | |
| 1570 | // Enforce page buffer cache constraints |
| 1571 | |
| 1572 | if (number < MIN_PAGE_BUFFERS) |
| 1573 | number = MIN_PAGE_BUFFERS; |
| 1574 | |
| 1575 | if (number > MAX_PAGE_BUFFERS) |
| 1576 | number = MAX_PAGE_BUFFERS; |
| 1577 | |
| 1578 | const ULONG count = number; |
| 1579 | |
| 1580 | // Allocate and initialize buffers control block |
| 1581 | BufferControl* bcb = BufferControl::create(dbb); |
| 1582 | while (true) |
| 1583 | { |
| 1584 | try |
| 1585 | { |
| 1586 | bcb->bcb_hashTable = FB_NEW_POOL(*bcb->bcb_bufferpool) |
| 1587 | BCBHashTable(*bcb->bcb_bufferpool, number); |
| 1588 | break; |
| 1589 | } |
| 1590 | catch (const Firebird::Exception& ex) |
| 1591 | { |
| 1592 | ex.stuffException(tdbb->tdbb_status_vector); |
| 1593 | |
| 1594 | number -= number >> 2; |
| 1595 | |
| 1596 | if (number < MIN_PAGE_BUFFERS) |
| 1597 | ERR_post(Arg::Gds(isc_cache_too_small)); |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | dbb->dbb_bcb = bcb; |
| 1602 | bcb->bcb_page_size = dbb->dbb_page_size; |
| 1603 | bcb->bcb_database = dbb; |
no test coverage detected