| 1511 | */ |
| 1512 | |
| 1513 | static HASH_LINK *get_hash_link(KEY_CACHE *keycache, |
| 1514 | int file, my_off_t filepos) |
| 1515 | { |
| 1516 | reg1 HASH_LINK *hash_link, **start; |
| 1517 | #if defined(KEYCACHE_DEBUG) |
| 1518 | int cnt; |
| 1519 | #endif |
| 1520 | |
| 1521 | KEYCACHE_DBUG_PRINT("get_hash_link", ("fd: %u pos: %lu", |
| 1522 | (uint) file,(ulong) filepos)); |
| 1523 | |
| 1524 | restart: |
| 1525 | /* |
| 1526 | Find the bucket in the hash table for the pair (file, filepos); |
| 1527 | start contains the head of the bucket list, |
| 1528 | hash_link points to the first member of the list |
| 1529 | */ |
| 1530 | hash_link= *(start= &keycache->hash_root[KEYCACHE_HASH(file, filepos)]); |
| 1531 | #if defined(KEYCACHE_DEBUG) |
| 1532 | cnt= 0; |
| 1533 | #endif |
| 1534 | /* Look for an element for the pair (file, filepos) in the bucket chain */ |
| 1535 | while (hash_link && |
| 1536 | (hash_link->diskpos != filepos || hash_link->file != file)) |
| 1537 | { |
| 1538 | hash_link= hash_link->next; |
| 1539 | #if defined(KEYCACHE_DEBUG) |
| 1540 | cnt++; |
| 1541 | if (! (cnt <= keycache->hash_links_used)) |
| 1542 | { |
| 1543 | int i; |
| 1544 | for (i=0, hash_link= *start ; |
| 1545 | i < cnt ; i++, hash_link= hash_link->next) |
| 1546 | { |
| 1547 | KEYCACHE_DBUG_PRINT("get_hash_link", ("fd: %u pos: %lu", |
| 1548 | (uint) hash_link->file,(ulong) hash_link->diskpos)); |
| 1549 | } |
| 1550 | } |
| 1551 | KEYCACHE_DBUG_ASSERT(cnt <= keycache->hash_links_used); |
| 1552 | #endif |
| 1553 | } |
| 1554 | if (! hash_link) |
| 1555 | { |
| 1556 | /* There is no hash link in the hash table for the pair (file, filepos) */ |
| 1557 | if (keycache->free_hash_list) |
| 1558 | { |
| 1559 | hash_link= keycache->free_hash_list; |
| 1560 | keycache->free_hash_list= hash_link->next; |
| 1561 | } |
| 1562 | else if (keycache->hash_links_used < keycache->hash_links) |
| 1563 | { |
| 1564 | hash_link= &keycache->hash_link_root[keycache->hash_links_used++]; |
| 1565 | } |
| 1566 | else |
| 1567 | { |
| 1568 | /* Wait for a free hash link */ |
| 1569 | struct st_my_thread_var *thread= my_thread_var; |
| 1570 | KEYCACHE_PAGE page; |
no test coverage detected