diff --git a/src/xrpld/app/consensus/ConsensusExtensions.h b/src/xrpld/app/consensus/ConsensusExtensions.h index 7af8577d5d..7d8b5aa3a8 100644 --- a/src/xrpld/app/consensus/ConsensusExtensions.h +++ b/src/xrpld/app/consensus/ConsensusExtensions.h @@ -654,8 +654,7 @@ public: void publishBusy() { - std::lock_guard lock(busyMu_); - busyPublished_.store(computeBusyUnlocked(), std::memory_order_relaxed); + publishBusyAfter([] {}); } // Phase changes happen in the tick, which is not a member. The store and @@ -692,6 +691,19 @@ public: } private: + // Compute and store the busy flag under one busyMu_ critical section. + // afterCompute runs between the two, on the publishing thread, with + // busyMu_ held; tests use it to hold a computed value before its store. + template + void + publishBusyAfter(AfterCompute&& afterCompute) + { + std::lock_guard lock(busyMu_); + auto const busy = computeBusyUnlocked(); + afterCompute(); + busyPublished_.store(busy, std::memory_order_relaxed); + } + bool computeBusyUnlocked() const {