]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/common/intrusive_lru.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / common / intrusive_lru.h
index 422c24a14fb615eb8deda188b93eea97d717015a..e8c3cda3e64e7d5c65098d751ffcfc173c9c6b90 100644 (file)
@@ -148,6 +148,33 @@ public:
     }
   }
 
+  /*
+   * Clears unreferenced elements from the lru set [from, to]
+   */
+  void clear_range(
+    const K& from,
+    const K& to) {
+      auto from_iter = lru_set.lower_bound(from);
+      auto to_iter = lru_set.upper_bound(to);
+      for (auto i = from_iter; i != to_iter; ) {
+        if (!(*i).lru) {
+          unreferenced_list.erase(lru_list_t::s_iterator_to(*i));
+          i = lru_set.erase_and_dispose(i, [](auto *p)
+            { delete p; } );
+        } else {
+          i++;
+        }
+      }
+  }
+
+  template <class F>
+  void for_each(F&& f) {
+    for (auto& v : lru_set) {
+      access(v);
+      f(TRef{static_cast<T*>(&v)});
+    }
+  }
+
   /**
    * Returns the TRef corresponding to k if it exists or
    * nullptr otherwise.
@@ -166,6 +193,10 @@ public:
     evict();
   }
 
+  ~intrusive_lru() {
+    set_target_size(0);
+  }
+
   friend void intrusive_ptr_add_ref<>(intrusive_lru_base<Config> *);
   friend void intrusive_ptr_release<>(intrusive_lru_base<Config> *);
 };