]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: Automatic reference to PerfCounters
authorAdam C. Emerson <aemerson@redhat.com>
Wed, 26 Jul 2017 22:11:19 +0000 (18:11 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Wed, 9 Aug 2017 02:53:12 +0000 (22:53 -0400)
PerfCountersRef is a unique_ptr using a deleter that unregisters the
managed PerfCounters on deletion.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/common/perf_counters.h

index e831b73ad68233b4e964fba74fadc4d7fc1b6227..507d09102de419cf9322800a71e6350986915172 100644 (file)
@@ -324,4 +324,19 @@ private:
   PerfCounters *m_perf_counters;
 };
 
+class PerfCountersDeleter {
+  CephContext* cct;
+
+public:
+  PerfCountersDeleter() noexcept : cct(nullptr) {}
+  PerfCountersDeleter(CephContext* cct) noexcept : cct(cct) {}
+  void operator()(PerfCounters* p) noexcept {
+    if (cct)
+      cct->get_perfcounters_collection()->remove(p);
+    delete p;
+  }
+};
+
+using PerfCountersRef = std::unique_ptr<PerfCounters, PerfCountersDeleter>;
+
 #endif