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.
This commit is contained in:
parent
86438ddb12
commit
c8b6debc43
1 changed files with 2 additions and 6 deletions
|
@ -73,18 +73,14 @@ nano::store::write_guard nano::store::write_queue::wait (writer writer)
|
|||
}
|
||||
|
||||
nano::unique_lock<nano::mutex> 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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue