![]() |
Bitcoin Core 31.99.0
P2P Digital Currency
|
Queue for verifications that have to be performed. More...
#include <checkqueue.h>
Public Member Functions | |
| CCheckQueue (unsigned int batch_size, int worker_threads_num) | |
| Create a new check queue. More... | |
| CCheckQueue (const CCheckQueue &)=delete | |
| CCheckQueue & | operator= (const CCheckQueue &)=delete |
| CCheckQueue (CCheckQueue &&)=delete | |
| CCheckQueue & | operator= (CCheckQueue &&)=delete |
| std::optional< R > | Complete () EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) |
| Join the execution until completion. More... | |
| void | Add (std::vector< T > &&vChecks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) |
| Add a batch of checks to the queue. More... | |
| ~CCheckQueue () | |
| bool | HasThreads () const |
Public Attributes | |
| Mutex | m_control_mutex |
| Mutex to ensure only one concurrent CCheckQueueControl. More... | |
Private Member Functions | |
| std::vector< T > queue | GUARDED_BY (m_mutex) |
| The queue of elements to be processed. More... | |
| int nIdle | GUARDED_BY (m_mutex) |
| The number of workers (including the master) that are idle. More... | |
| int nTotal | GUARDED_BY (m_mutex) |
| The total number of workers (including the master). More... | |
| std::optional< R > m_result | GUARDED_BY (m_mutex) |
| The temporary evaluation result. More... | |
| unsigned int nTodo | GUARDED_BY (m_mutex) |
| Number of verifications that haven't completed yet. More... | |
| bool m_request_stop | GUARDED_BY (m_mutex) |
| std::optional< R > | Loop (bool fMaster) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) |
| More... | |
Private Attributes | |
| Mutex | m_mutex |
| Mutex to protect the inner state. More... | |
| std::condition_variable | m_worker_cv |
| Worker threads block on this when out of work. More... | |
| std::condition_variable | m_master_cv |
| Master thread blocks on this when out of work. More... | |
| const unsigned int | nBatchSize |
| The maximum number of elements to be processed in one batch. More... | |
| std::vector< std::thread > | m_worker_threads |
Queue for verifications that have to be performed.
The verifications are represented by a type T, which must provide an operator(), returning an std::optional<R>.
The overall result of the computation is std::nullopt if all invocations return std::nullopt, or one of the other results otherwise.
One thread (the master) is assumed to push batches of verifications onto the queue, where they are processed by N-1 worker threads. When the master is done adding work, it temporarily joins the worker pool as an N'th worker, until all jobs are done.
Definition at line 33 of file checkqueue.h.
|
inlineexplicit |
Create a new check queue.
Definition at line 145 of file checkqueue.h.
|
delete |
|
delete |
|
inline |
Definition at line 192 of file checkqueue.h.
|
inline |
Add a batch of checks to the queue.
Definition at line 173 of file checkqueue.h.
|
inline |
Join the execution until completion.
If at least one evaluation wasn't successful, return its error.
Definition at line 167 of file checkqueue.h.
|
private |
The queue of elements to be processed.
As the order of booleans doesn't matter, it is used as a LIFO (stack)
|
inlineprivate |
The number of workers (including the master) that are idle.
Definition at line 50 of file checkqueue.h.
|
inlineprivate |
The total number of workers (including the master).
Definition at line 53 of file checkqueue.h.
|
private |
The temporary evaluation result.
|
inlineprivate |
Number of verifications that haven't completed yet.
This includes elements that are no longer queued, but still in the worker's own batches.
Definition at line 63 of file checkqueue.h.
|
inlineprivate |
Definition at line 69 of file checkqueue.h.
|
inline |
Definition at line 201 of file checkqueue.h.
|
inlineprivate |
Internal function that does bulk of the verification work. If fMaster, return the final result.
Definition at line 73 of file checkqueue.h.
|
delete |
|
delete |
| Mutex CCheckQueue< T, R >::m_control_mutex |
Mutex to ensure only one concurrent CCheckQueueControl.
Definition at line 142 of file checkqueue.h.
|
private |
Master thread blocks on this when out of work.
Definition at line 43 of file checkqueue.h.
|
private |
Mutex to protect the inner state.
Definition at line 37 of file checkqueue.h.
|
private |
Worker threads block on this when out of work.
Definition at line 40 of file checkqueue.h.
|
private |
Definition at line 68 of file checkqueue.h.
|
private |
The maximum number of elements to be processed in one batch.
Definition at line 66 of file checkqueue.h.