Compare commits

...

3 Commits

Author SHA1 Message Date
JCW
ccb489c139 Refactor to make the code simpler
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
2026-02-06 11:18:51 +00:00
JCW
50dcc138db Refactor to make the code simpler
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
2026-02-06 11:12:36 +00:00
JCW
947698f554 Fix the memory ordering issue on ARM for Workers
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
2026-01-30 12:24:18 +00:00
2 changed files with 12 additions and 22 deletions

View File

@@ -1,5 +1,4 @@
#ifndef XRPL_CORE_WORKERS_H_INCLUDED
#define XRPL_CORE_WORKERS_H_INCLUDED
#pragma once
#include <xrpl/beast/core/LockFreeStack.h>
#include <xrpl/core/detail/semaphore.h>
@@ -194,10 +193,8 @@ private:
private:
Callback& m_callback;
perf::PerfLog* perfLog_;
std::string m_threadNames; // The name to give each thread
std::condition_variable m_cv; // signaled when all threads paused
std::string m_threadNames; // The name to give each thread
std::mutex m_mut;
bool m_allPaused;
semaphore m_semaphore; // each pending task is 1 resource
int m_numberOfThreads; // how many we want active now
std::atomic<int> m_activeCount; // to know when all are paused
@@ -208,5 +205,3 @@ private:
};
} // namespace xrpl
#endif

View File

@@ -9,7 +9,6 @@ Workers::Workers(Callback& callback, perf::PerfLog* perfLog, std::string const&
: m_callback(callback)
, perfLog_(perfLog)
, m_threadNames(threadNames)
, m_allPaused(true)
, m_semaphore(0)
, m_numberOfThreads(0)
, m_activeCount(0)
@@ -92,9 +91,12 @@ Workers::stop()
{
setNumberOfThreads(0);
std::unique_lock<std::mutex> lk{m_mut};
m_cv.wait(lk, [this] { return m_allPaused; });
lk.unlock();
int activeCount = m_activeCount.load();
while (activeCount != 0)
{
m_activeCount.wait(activeCount);
activeCount = m_activeCount.load();
}
XRPL_ASSERT(numberOfCurrentlyRunningTasks() == 0, "xrpl::Workers::stop : zero running tasks");
}
@@ -167,11 +169,8 @@ Workers::Worker::run()
// Increment the count of active workers, and if
// we are the first one then reset the "all paused" event
//
if (++m_workers.m_activeCount == 1)
{
std::lock_guard lk{m_workers.m_mut};
m_workers.m_allPaused = false;
}
++m_workers.m_activeCount;
m_workers.m_activeCount.notify_all();
for (;;)
{
@@ -221,12 +220,8 @@ Workers::Worker::run()
// Decrement the count of active workers, and if we
// are the last one then signal the "all paused" event.
//
if (--m_workers.m_activeCount == 0)
{
std::lock_guard lk{m_workers.m_mut};
m_workers.m_allPaused = true;
m_workers.m_cv.notify_all();
}
--m_workers.m_activeCount;
m_workers.m_activeCount.notify_all();
// Set inactive thread name.
beast::setCurrentThreadName("(" + threadName_ + ")");