| 954 | } |
| 955 | |
| 956 | void LIRSCacheShard::UpdateCharge(HandleBase* handle, size_t charge) { |
| 957 | DCHECK(initialized_); |
| 958 | LIRSThreadState tstate; |
| 959 | { |
| 960 | // Hold the lock to avoid concurrent evictions |
| 961 | std::lock_guard<MutexType> l(mutex_); |
| 962 | LIRSHandle* e = static_cast<LIRSHandle*>(handle); |
| 963 | // Entries that are UNINITIALIZED or TOMBSTONE do not count towards |
| 964 | // the usage and will be destroyed without interacting with the usage. |
| 965 | // Skip modifying the charge. |
| 966 | // |
| 967 | // In the case of UNINITIALIZED, we know that the caller has a handle |
| 968 | // for the entry, so it needs to have been in the cache previously |
| 969 | // (i.e. it was found via Lookup() or added via Insert()). So, in this |
| 970 | // context, UNINITIALIZED can only mean that it has been evicted. |
| 971 | if (e->state() == UNINITIALIZED || e->state() == TOMBSTONE) { |
| 972 | return; |
| 973 | } |
| 974 | DCHECK(e->state() == PROTECTED || e->state() == UNPROTECTED); |
| 975 | int64_t delta = charge - handle->charge(); |
| 976 | handle->set_charge(charge); |
| 977 | UpdateMemTracker(delta); |
| 978 | // Update usage in existing state, then evict as needed. |
| 979 | switch (e->state()) { |
| 980 | case PROTECTED: |
| 981 | protected_usage_ += delta; |
| 982 | EnforceProtectedCapacity(&tstate); |
| 983 | break; |
| 984 | case UNPROTECTED: |
| 985 | unprotected_usage_ += delta; |
| 986 | EnforceUnprotectedCapacity(&tstate); |
| 987 | break; |
| 988 | default: |
| 989 | // This can't happen. |
| 990 | CHECK(false) << "Unexpected state for UpdateCharge: " << e->state(); |
| 991 | break; |
| 992 | } |
| 993 | } |
| 994 | CleanupThreadState(&tstate); |
| 995 | } |
| 996 | |
| 997 | void LIRSCacheShard::Release(HandleBase* handle) { |
| 998 | DCHECK(initialized_); |
nothing calls this directly
no test coverage detected