summaryrefslogtreecommitdiffstats
path: root/src/common/Finisher.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/Finisher.cc')
-rw-r--r--src/common/Finisher.cc33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/common/Finisher.cc b/src/common/Finisher.cc
index ff931faffc1..43550f35197 100644
--- a/src/common/Finisher.cc
+++ b/src/common/Finisher.cc
@@ -2,11 +2,40 @@
// vim: ts=8 sw=2 smarttab
#include "Finisher.h"
+#include "common/perf_counters.h"
+
+#include <fmt/core.h>
#define dout_subsys ceph_subsys_finisher
#undef dout_prefix
#define dout_prefix *_dout << "finisher(" << this << ") "
+Finisher::Finisher(CephContext *cct_) :
+ cct(cct_), finisher_lock(ceph::make_mutex("Finisher::finisher_lock")),
+ thread_name("fn_anonymous"),
+ finisher_thread(this) {}
+
+Finisher::Finisher(CephContext *cct_, std::string_view name, std::string &&tn) :
+ cct(cct_), finisher_lock(ceph::make_mutex(fmt::format("Finisher::{}", name))),
+ thread_name(std::move(tn)),
+ finisher_thread(this) {
+ PerfCountersBuilder b(cct, fmt::format("finisher-{}", name),
+ l_finisher_first, l_finisher_last);
+ b.add_u64(l_finisher_queue_len, "queue_len");
+ b.add_time_avg(l_finisher_complete_lat, "complete_latency");
+ logger = b.create_perf_counters();
+ cct->get_perfcounters_collection()->add(logger);
+ logger->set(l_finisher_queue_len, 0);
+ logger->set(l_finisher_complete_lat, 0);
+}
+
+Finisher::~Finisher() {
+ if (logger && cct) {
+ cct->get_perfcounters_collection()->remove(logger);
+ delete logger;
+ }
+}
+
void Finisher::start()
{
ldout(cct, 10) << __func__ << dendl;
@@ -20,7 +49,7 @@ void Finisher::stop()
finisher_stop = true;
// we don't have any new work to do, but we want the worker to wake up anyway
// to process the stop condition.
- finisher_cond.notify_all();
+ finisher_cond.notify_one();
finisher_lock.unlock();
finisher_thread.join(); // wait until the worker exits completely
ldout(cct, 10) << __func__ << " finish" << dendl;
@@ -40,7 +69,7 @@ void Finisher::wait_for_empty()
bool Finisher::is_empty()
{
- std::unique_lock ul(finisher_lock);
+ const std::lock_guard l{finisher_lock};
return finisher_queue.empty();
}