1#include <xrpl/core/detail/Workers.h>
3#include <xrpl/beast/core/CurrentThreadName.h>
4#include <xrpl/beast/core/LockFreeStack.h>
5#include <xrpl/core/PerfLog.h>
49 static int kInstance{0};
54 perfLog_->resizeJobs(numberOfThreads);
61 for (
int i = 0; i < amount; ++i)
66 if (worker !=
nullptr)
85 for (
int i = 0; i < amount; ++i)
130 if (worker !=
nullptr)
174 bool shouldExit =
true;
198 int pauseCount =
workers_.pauseCount_.load();
203 pauseCount = --
workers_.pauseCount_;
227 if (--
workers_.runningTaskCount_ == 0)
266 }
while (!shouldExit);
Multiple Producer, Multiple Consumer (MPMC) intrusive stack.
Element * popFront()
Pop an element off the stack.
std::string const threadName_
Worker(Workers &workers, std::string threadName, int const instance)
std::condition_variable wakeup_
void setNumberOfThreads(int numberOfThreads)
Set the desired number of threads.
void stop()
Pause all threads and wait until they are paused.
std::atomic< int > activeCount_
beast::LockFreeStack< Worker, PausedTag > paused_
int numberOfCurrentlyRunningTasks() const noexcept
Get the number of currently executing calls of Callback::processTask.
std::atomic< int > pauseCount_
void addTask()
Add a task to be performed.
Workers(Callback &callback, perf::PerfLog *perfLog, std::string threadNames="Worker", int numberOfThreads=static_cast< int >(std::thread::hardware_concurrency()))
Create the object.
static void deleteWorkers(beast::LockFreeStack< Worker > &stack)
std::condition_variable cv_
std::atomic< int > runningTaskCount_
beast::LockFreeStack< Worker > everyone_
int getNumberOfThreads() const noexcept
Retrieve the desired number of threads.
Singleton class that maintains performance counters and optionally writes Json-formatted data to a di...
void setCurrentThreadName(std::string_view newThreadName)
Changes the name of the caller thread.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Called to perform tasks as needed.