]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/Finisher: do not wake up the thread if already running
authorMax Kellermann <max.kellermann@ionos.com>
Mon, 7 Oct 2024 20:12:41 +0000 (22:12 +0200)
committerMax Kellermann <max.kellermann@ionos.com>
Thu, 10 Oct 2024 05:31:52 +0000 (07:31 +0200)
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 <max.kellermann@ionos.com>
src/common/Finisher.h

index 81211c822694accd47767dca7311875531fc53dd..215930116d35c1ab13c4dbfa87ace3a950e6c6ec 100644 (file)
@@ -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) {