| 713 | } |
| 714 | |
| 715 | void LIRSCacheShard::UnprotectedToTombstone(LIRSThreadState* tstate, LIRSHandle* e) { |
| 716 | // Decrement unprotected usage |
| 717 | DCHECK(e->unprotected_tombstone_list_hook_.is_linked()); |
| 718 | DCHECK(e->recency_list_hook_.is_linked()); |
| 719 | |
| 720 | // Optimized code to go from UNPROTECTED to TOMBSTONE without adding/removing |
| 721 | // it from a list. Only the unprotected_list_front_ moves. |
| 722 | DCHECK_EQ(e, unprotected_list_front_); |
| 723 | if (num_unprotected_ > 1) { |
| 724 | // There is some other UNPROTECTED entry |
| 725 | auto it = unprotected_tombstone_list_.iterator_to(*e); |
| 726 | ++it; |
| 727 | unprotected_list_front_ = &*it; |
| 728 | } else { |
| 729 | // This was the only UNPROTECTED entry, the unprotected list is empty |
| 730 | unprotected_list_front_ = nullptr; |
| 731 | } |
| 732 | |
| 733 | // Set state to TOMBSTONE. If there are currently no references, this thread is |
| 734 | // responsible for eviction, so it must also set the residency to EVICTING. |
| 735 | auto state_transition = e->modify_atomic_state([](AtomicState& cur_state) { |
| 736 | DCHECK_EQ(cur_state.state, UNPROTECTED); |
| 737 | DCHECK_EQ(cur_state.residency, RESIDENT); |
| 738 | cur_state.state = TOMBSTONE; |
| 739 | if (cur_state.ref_count == 0) cur_state.residency = EVICTING; |
| 740 | }); |
| 741 | // Look at the old state. If there are no references, then we can immediately evict. |
| 742 | if (state_transition.before.ref_count == 0) { |
| 743 | tstate->handles_to_evict.push_back(e); |
| 744 | } |
| 745 | // List operations happen before changes to the counts/usage |
| 746 | --num_unprotected_; |
| 747 | ++num_tombstones_; |
| 748 | |
| 749 | // This will be evicted, so the charge disappears |
| 750 | unprotected_usage_ -= e->charge(); |
| 751 | EnforceTombstoneLimit(tstate); |
| 752 | } |
| 753 | |
| 754 | void LIRSCacheShard::UninitializedToProtected(LIRSThreadState* tstate, LIRSHandle* e) { |
| 755 | DCHECK(!e->unprotected_tombstone_list_hook_.is_linked()); |
nothing calls this directly
no test coverage detected