Skip to content

Commit 87648ed

Browse files
authored
Merge pull request ceph#61213 from Matan-B/wip-matanb-crimson-shared-lru-dtor
crimson/common/shared_lru: invalidate Deleter's cache Reviewed-by: Yingxin Cheng <[email protected]> Reviewed-by: Samuel Just <[email protected]>
2 parents 29f31e6 + 7989e98 commit 87648ed

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/crimson/common/shared_lru.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ class SharedLRU {
2525
SimpleLRU<K, shared_ptr_t, false> cache;
2626
std::map<K, std::pair<weak_ptr_t, V*>> weak_refs;
2727

28+
// Once all of the shared pointers are destoryed,
29+
// erase the tracked object from the weak_ref map
30+
// before actually destorying it
2831
struct Deleter {
29-
SharedLRU<K,V>* cache;
32+
SharedLRU<K,V>* shared_lru_ptr;
3033
const K key;
31-
void operator()(V* ptr) {
32-
cache->_erase_weak(key);
33-
delete ptr;
34+
void operator()(V* value_ptr) {
35+
if (shared_lru_ptr) {
36+
shared_lru_ptr->_erase_weak(key);
37+
}
38+
delete value_ptr;
3439
}
3540
};
3641
void _erase_weak(const K& key) {
@@ -42,9 +47,19 @@ class SharedLRU {
4247
{}
4348
~SharedLRU() {
4449
cache.clear();
50+
4551
// initially, we were assuming that no pointer obtained from SharedLRU
4652
// can outlive the lru itself. However, since going with the interruption
4753
// concept for handling shutdowns, this is no longer valid.
54+
// Moreover, before clearing weak_refs, invalidate each deleter
55+
// cache pointer as this SharedLRU is being destoryed.
56+
for (const auto& [key, value] : weak_refs) {
57+
shared_ptr_t val;
58+
val = value.first.lock();
59+
auto this_deleter = get_deleter<Deleter>(val);
60+
this_deleter->shared_lru_ptr = nullptr;
61+
}
62+
4863
weak_refs.clear();
4964
}
5065
/**

0 commit comments

Comments
 (0)