mirror of
https://github.com/XRPLF/rippled.git
synced 2026-02-13 10:22:30 +00:00
Compare commits
3 Commits
bthomee/no
...
a1q123456/
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccb489c139 | ||
|
|
50dcc138db | ||
|
|
947698f554 |
@@ -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
|
||||
|
||||
@@ -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_ + ")");
|
||||
|
||||
Reference in New Issue
Block a user