From: Max Kellermann Date: Mon, 7 Oct 2024 19:13:22 +0000 (+0200) Subject: common/Finisher: use `std::lock_guard` instead of `std::unique_lock` X-Git-Tag: v20.0.0~789^2~12 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5b97c09b6f02dc91f98d4ce70e7bb50ab2d26840;p=ceph.git common/Finisher: use `std::lock_guard` instead of `std::unique_lock` `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 --- diff --git a/src/common/Finisher.cc b/src/common/Finisher.cc index ff931faffc1..20b8829d7ec 100644 --- a/src/common/Finisher.cc +++ b/src/common/Finisher.cc @@ -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(); } diff --git a/src/common/Finisher.h b/src/common/Finisher.h index baf02bd26a4..46a4599b8d0 100644 --- a/src/common/Finisher.h +++ b/src/common/Finisher.h @@ -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 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(); }