refactor(consensus): compute and store the busy flag through one private template

publishBusy() delegates to publishBusyAfter(), which keeps the same busyMu_ critical section, predicate and relaxed store, and runs a caller-supplied step between compute and store. Production passes an empty step; tests use it to hold a computed value before its store.
This commit is contained in:
Nicholas Dudfield
2026-09-25 10:37:49 +07:00
parent 4d4c5aa43a
commit b92ef011bf

View File

@@ -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 <class AfterCompute>
void
publishBusyAfter(AfterCompute&& afterCompute)
{
std::lock_guard lock(busyMu_);
auto const busy = computeBusyUnlocked();
afterCompute();
busyPublished_.store(busy, std::memory_order_relaxed);
}
bool
computeBusyUnlocked() const
{