From: Igor Fedotov Date: Mon, 5 Aug 2019 14:38:09 +0000 (+0300) Subject: common/Finisher: kill the need for lock for ContextQueue::empty() X-Git-Tag: v15.1.0~1919^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=c2c8491f1fdf0cb5c2a9a5980a3e153d95126b01;p=ceph-ci.git common/Finisher: kill the need for lock for ContextQueue::empty() Signed-off-by: Igor Fedotov --- diff --git a/src/common/Finisher.h b/src/common/Finisher.h index d76674027c7..3b6f9e45523 100644 --- a/src/common/Finisher.h +++ b/src/common/Finisher.h @@ -195,24 +195,26 @@ class ContextQueue { std::mutex q_mutex; ceph::mutex& mutex; ceph::condition_variable& cond; + std::atomic_bool q_empty = true; public: ContextQueue(ceph::mutex& mut, ceph::condition_variable& con) : mutex(mut), cond(con) {} void queue(std::list& ls) { - bool empty = false; + bool was_empty = false; { std::scoped_lock l(q_mutex); if (q.empty()) { q.swap(ls); - empty = true; + was_empty = true; } else { q.insert(q.end(), ls.begin(), ls.end()); } + q_empty = q.empty(); } - if (empty) { + if (was_empty) { std::scoped_lock l{mutex}; cond.notify_all(); } @@ -226,11 +228,11 @@ public: if (!q.empty()) { q.swap(ls); } + q_empty = true; } bool empty() { - std::scoped_lock l(q_mutex); - return q.empty(); + return q_empty; } };