summaryrefslogtreecommitdiffstats
path: root/src/crimson/common/shared_lru.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/crimson/common/shared_lru.h')
-rw-r--r--src/crimson/common/shared_lru.h23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/crimson/common/shared_lru.h b/src/crimson/common/shared_lru.h
index 92d99d332c4..0d73658e709 100644
--- a/src/crimson/common/shared_lru.h
+++ b/src/crimson/common/shared_lru.h
@@ -25,12 +25,17 @@ class SharedLRU {
SimpleLRU<K, shared_ptr_t, false> cache;
std::map<K, std::pair<weak_ptr_t, V*>> weak_refs;
+ // Once all of the shared pointers are destoryed,
+ // erase the tracked object from the weak_ref map
+ // before actually destorying it
struct Deleter {
- SharedLRU<K,V>* cache;
+ SharedLRU<K,V>* shared_lru_ptr;
const K key;
- void operator()(V* ptr) {
- cache->_erase_weak(key);
- delete ptr;
+ void operator()(V* value_ptr) {
+ if (shared_lru_ptr) {
+ shared_lru_ptr->_erase_weak(key);
+ }
+ delete value_ptr;
}
};
void _erase_weak(const K& key) {
@@ -42,9 +47,19 @@ public:
{}
~SharedLRU() {
cache.clear();
+
// initially, we were assuming that no pointer obtained from SharedLRU
// can outlive the lru itself. However, since going with the interruption
// concept for handling shutdowns, this is no longer valid.
+ // Moreover, before clearing weak_refs, invalidate each deleter
+ // cache pointer as this SharedLRU is being destoryed.
+ for (const auto& [key, value] : weak_refs) {
+ shared_ptr_t val;
+ val = value.first.lock();
+ auto this_deleter = get_deleter<Deleter>(val);
+ this_deleter->shared_lru_ptr = nullptr;
+ }
+
weak_refs.clear();
}
/**