From 34706ef0ac4ce67bacf44f64dc0b2381304d3847 Mon Sep 17 00:00:00 2001 From: JCW Date: Thu, 18 Sep 2025 23:48:31 +0100 Subject: [PATCH] Fix test case bug Signed-off-by: JCW --- src/test/core/JobQueue_test.cpp | 2 ++ src/xrpld/core/Coro.ipp | 12 +++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/core/JobQueue_test.cpp b/src/test/core/JobQueue_test.cpp index 66d24bc4c9..a837425d73 100644 --- a/src/test/core/JobQueue_test.cpp +++ b/src/test/core/JobQueue_test.cpp @@ -87,6 +87,8 @@ class JobQueue_test : public beast::unit_test::suite while (yieldCount == 0) ; + coro->join(); + // Now re-post until the Coro says it is done. int old = yieldCount; while (coro->runnable()) diff --git a/src/xrpld/core/Coro.ipp b/src/xrpld/core/Coro.ipp index 1c2eac64a6..fcbfe02145 100644 --- a/src/xrpld/core/Coro.ipp +++ b/src/xrpld/core/Coro.ipp @@ -83,11 +83,9 @@ JobQueue::Coro::yield() if (shouldStop()) return; - { - std::lock_guard stateLock{mutex_run_}; - state_ = CoroState::Suspended; - cv_.notify_all(); - } + state_ = CoroState::Suspended; + cv_.notify_all(); + ++jq_.nSuspend_; jq_.m_suspendedCoros[this] = weak_from_this(); jq_.cv_.notify_all(); @@ -115,11 +113,11 @@ inline void JobQueue::Coro::resume() { { - if (state_ != CoroState::Suspended) + auto suspended = CoroState::Suspended; + if (!state_.compare_exchange_strong(suspended, CoroState::Running)) { return; } - state_ = CoroState::Running; cv_.notify_all(); } {