From: Max Kellermann Date: Mon, 7 Oct 2024 20:12:41 +0000 (+0200) Subject: common/Finisher: do not wake up the thread if already running X-Git-Tag: v20.0.0~789^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e30551eb86cfde834e3b759e3cb99b783bc57371;p=ceph.git common/Finisher: do not wake up the thread if already running If `finisher_running` is set, then the `Finisher` thread will automatically pick up new items queued by other threads. It is therefore not needed to wake it up and we can eliminate one system call. Signed-off-by: Max Kellermann --- diff --git a/src/common/Finisher.h b/src/common/Finisher.h index 81211c82269..215930116d3 100644 --- a/src/common/Finisher.h +++ b/src/common/Finisher.h @@ -67,9 +67,9 @@ class Finisher { void queue(Context *c, int r = 0) { { const std::lock_guard l{finisher_lock}; - const bool was_empty = finisher_queue.empty(); + const bool should_notify = finisher_queue.empty() && !finisher_running; finisher_queue.push_back(std::make_pair(c, r)); - if (was_empty) { + if (should_notify) { finisher_cond.notify_one(); } } @@ -83,7 +83,7 @@ class Finisher { auto queue(T &ls) -> decltype(std::distance(ls.begin(), ls.end()), void()) { { const std::lock_guard l{finisher_lock}; - if (finisher_queue.empty()) { + if (finisher_queue.empty() && !finisher_running) { finisher_cond.notify_all(); } for (Context *i : ls) {