| 541 | } |
| 542 | |
| 543 | size_t NvmLRUCache::Invalidate(const Cache::InvalidationControl& ctl) { |
| 544 | size_t invalid_entry_count = 0; |
| 545 | size_t valid_entry_count = 0; |
| 546 | LRUHandle* to_remove_head = nullptr; |
| 547 | |
| 548 | { |
| 549 | std::lock_guard<MutexType> l(mutex_); |
| 550 | |
| 551 | // rl_.next is the oldest entry in the recency list. |
| 552 | LRUHandle* h = lru_.next; |
| 553 | while (h != nullptr && h != &lru_ && |
| 554 | ctl.iteration_func(valid_entry_count, invalid_entry_count)) { |
| 555 | if (ctl.validity_func(h->key(), h->value())) { |
| 556 | // Continue iterating over the list. |
| 557 | h = h->next; |
| 558 | ++valid_entry_count; |
| 559 | continue; |
| 560 | } |
| 561 | // Copy the handle slated for removal. |
| 562 | LRUHandle* h_to_remove = h; |
| 563 | // Prepare for next iteration of the cycle. |
| 564 | h = h->next; |
| 565 | |
| 566 | NvmLRU_Remove(h_to_remove); |
| 567 | table_.Remove(h_to_remove->key(), h_to_remove->hash); |
| 568 | if (Unref(h_to_remove)) { |
| 569 | h_to_remove->next = to_remove_head; |
| 570 | to_remove_head = h_to_remove; |
| 571 | } |
| 572 | ++invalid_entry_count; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | FreeLRUEntries(to_remove_head); |
| 577 | |
| 578 | return invalid_entry_count; |
| 579 | } |
| 580 | |
| 581 | // Determine the number of bits of the hash that should be used to determine |
| 582 | // the cache shard. This, in turn, determines the number of shards. |
no test coverage detected