]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/Finisher: use `std::lock_guard` instead of `std::unique_lock`
authorMax Kellermann <max.kellermann@ionos.com>
Mon, 7 Oct 2024 19:13:22 +0000 (21:13 +0200)
committerMax Kellermann <max.kellermann@ionos.com>
Thu, 10 Oct 2024 05:31:52 +0000 (07:31 +0200)
`std::lock_guard` is all we need here, and the added complexity of
`std::unique_lock` is not used and is usually optimized away by the
compiler.  Using `std::lock_guard` directly will reduce the amount of
work that the optimizer needs to do and saves some build CPU cycles.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
src/common/Finisher.cc
src/common/Finisher.h

index ff931faffc1af1a05830bb987d389d0100b9d835..20b8829d7ecdde200f72c6a25c731f6acbbbe92e 100644 (file)
@@ -40,7 +40,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();
 }
 
index baf02bd26a44720c12b54ae1efd47cdedfa68180..46a4599b8d000113f696a2bb33a5f630303f5631 100644 (file)
@@ -65,7 +65,7 @@ class Finisher {
  public:
   /// Add a context to complete, optionally specifying a parameter for the complete function.
   void queue(Context *c, int r = 0) {
-    std::unique_lock ul(finisher_lock);
+    const std::lock_guard l{finisher_lock};
     bool was_empty = finisher_queue.empty();
     finisher_queue.push_back(std::make_pair(c, r));
     if (was_empty) {
@@ -79,7 +79,7 @@ class Finisher {
   template<typename T>
   auto queue(T &ls) -> decltype(std::distance(ls.begin(), ls.end()), void()) {
     {
-      std::unique_lock ul(finisher_lock);
+      const std::lock_guard l{finisher_lock};
       if (finisher_queue.empty()) {
        finisher_cond.notify_all();
       }