mirror of
https://github.com/Xahau/xahaud.git
synced 2026-09-27 15:38:01 +00:00
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:
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user