 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
5 #ifndef BITCOIN_CHECKQUEUE_H
6 #define BITCOIN_CHECKQUEUE_H
72 std::vector<T> vChecks;
74 unsigned int nNow = 0;
83 if (nTodo == 0 && !fMaster)
91 while (queue.empty() && !m_request_stop) {
92 if (fMaster && nTodo == 0) {
104 if (m_request_stop) {
113 nNow = std::max(1U, std::min(
nBatchSize, (
unsigned int)queue.size() / (nTotal + nIdle + 1)));
114 vChecks.resize(nNow);
115 for (
unsigned int i = 0; i < nNow; i++) {
118 vChecks[i].swap(queue.back());
125 for (
T& check : vChecks)
152 for (
int n = 0; n < threads_num; ++n) {
168 void Add(std::vector<T>& vChecks)
170 if (vChecks.empty()) {
176 for (
T& check : vChecks) {
177 queue.emplace_back();
178 check.swap(queue.back());
180 nTodo += vChecks.size();
183 if (vChecks.size() == 1) {
213 template <
typename T>
236 bool fRet =
pqueue->Wait();
241 void Add(std::vector<T>& vChecks)
257 #endif // BITCOIN_CHECKQUEUE_H
void StopWorkerThreads()
Stop all of the worker threads.
const unsigned int nBatchSize
The maximum number of elements to be processed in one batch.
int nTotal GUARDED_BY(m_mutex)
The total number of workers (including the master).
bool Loop(bool fMaster)
Internal function that does bulk of the verification work.
void StartWorkerThreads(const int threads_num)
Create a pool of new worker threads.
std::vector< T > queue GUARDED_BY(m_mutex)
The queue of elements to be processed.
CCheckQueueControl & operator=(const CCheckQueueControl &)=delete
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
CCheckQueue(unsigned int nBatchSizeIn)
Create a new check queue.
@ VALIDATION_SCRIPT_CHECK
void Add(std::vector< T > &vChecks)
#define ENTER_CRITICAL_SECTION(cs)
Mutex m_mutex
Mutex to protect the inner state.
CCheckQueue< T > *const pqueue
bool fAllOk GUARDED_BY(m_mutex)
The temporary evaluation result.
Queue for verifications that have to be performed.
int nIdle GUARDED_BY(m_mutex)
The number of workers (including the master) that are idle.
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name.
void SetSyscallSandboxPolicy(SyscallSandboxPolicy syscall_policy)
Force the current thread (and threads created from the current thread) into a restricted-service oper...
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
bool m_request_stop GUARDED_BY(m_mutex)
std::condition_variable m_master_cv
Master thread blocks on this when out of work.
CCheckQueueControl()=delete
Mutex m_control_mutex
Mutex to ensure only one concurrent CCheckQueueControl.
std::vector< std::thread > m_worker_threads
#define LEAVE_CRITICAL_SECTION(cs)
CCheckQueueControl(CCheckQueue< T > *const pqueueIn)
void Add(std::vector< T > &vChecks)
Add a batch of checks to the queue.
#define WAIT_LOCK(cs, name)
std::condition_variable m_worker_cv
Worker threads block on this when out of work.
bool Wait()
Wait until execution finishes, and return whether all evaluations were successful.