From c8b6debc43acf78f95d75e4622736191c614b5a8 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Fri, 12 Apr 2024 20:09:50 +0100 Subject: [PATCH] Clean up write_queue::wait. Add consistency check to ensure the writer token is not already queued since they're waited for by value. Change wait-loop to use the predicated overload of wait. --- nano/store/write_queue.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/nano/store/write_queue.cpp b/nano/store/write_queue.cpp index cdc7f41f..b50809a3 100644 --- a/nano/store/write_queue.cpp +++ b/nano/store/write_queue.cpp @@ -73,18 +73,14 @@ nano::store::write_guard nano::store::write_queue::wait (writer writer) } nano::unique_lock lk (mutex); + debug_assert (std::none_of (queue.cbegin (), queue.cend (), [writer] (auto const & item) { return item == writer; })); // Add writer to the end of the queue if it's not already waiting auto exists = std::find (queue.cbegin (), queue.cend (), writer) != queue.cend (); if (!exists) { queue.push_back (writer); } - - while (queue.front () != writer) - { - cv.wait (lk); - } - + cv.wait (lk, [&] () { return queue.front () == writer; }); return write_guard (guard_finish_callback); }