This class handles concurrent execution of tasks. More...
#include <TaskRunner.h>

Public Member Functions | |
TaskRunner () | |
Constructor. More... | |
TaskRunner (unsigned int threadCount) | |
Constructor. More... | |
virtual | ~TaskRunner ()=default |
TaskRunner (const TaskRunner &other)=delete | |
TaskRunner & | operator= (const TaskRunner &other)=delete |
void | AddTask (std::unique_ptr< Task > task) |
Adds a task to the task queue. This should only be called from one thread. More... | |
void | Run () |
Runs all tasks and waits for completion. More... | |
virtual std::unique_ptr< Task > | GetNextTask () override |
Removes and returns the next task from the task queue. If the queue is empty, a null pointer is returned. More... | |
void | EchoProgress (bool echo) |
virtual void | ReportTaskComplete () override |
Notification that a task is complete. More... | |
Private Member Functions | |
void | PrintProgress () |
Prints a text progress bar based on the number of tasks there were in the queue when execution began and the number of reported task completions. More... | |
Private Attributes | |
std::recursive_mutex | m_taskQueueMutex |
Mutex used to synchronize concurrent access to the task queue. More... | |
std::queue< std::unique_ptr< Task > > | m_tasks |
Queue of tasks to be run. More... | |
unsigned int | m_threadCount = 1 |
The number of threads to spawn when running tasks. More... | |
bool | m_echoPercentComplete = false |
Whether or not the task runner should output percent complete as it executes. More... | |
unsigned int | m_totalTaskCount = 0 |
Total number of tasks in the queue when the task running begins to execute. More... | |
unsigned int | m_tasksComplete = 0 |
Number of completed tasks. More... | |
Detailed Description
This class handles concurrent execution of tasks.
Constructor & Destructor Documentation
biogears::TaskRunner::TaskRunner | ( | ) |
Constructor.
The default constructor sets the thread count to the number of cores on the machine as determined by std::thread::hardware_concurrency(). In the case that the number of cores cannot be determined, the TaskRunner runs in single-threaded mode.
biogears::TaskRunner::TaskRunner | ( | unsigned int | threadCount | ) |
Constructor.
- Parameters
-
threadCount number of threads to use
|
virtualdefault |
|
delete |
Member Function Documentation
void biogears::TaskRunner::AddTask | ( | std::unique_ptr< Task > | task | ) |
Adds a task to the task queue. This should only be called from one thread.
- Parameters
-
task Unique pointer to the task to add
|
inline |
|
overridevirtual |
Removes and returns the next task from the task queue. If the queue is empty, a null pointer is returned.
- Returns
- Pointer to the next task, or a null pointer if there are no tasks
Implements biogears::TaskQueue.
|
delete |
|
private |
Prints a text progress bar based on the number of tasks there were in the queue when execution began and the number of reported task completions.
|
overridevirtual |
Notification that a task is complete.
Implements biogears::TaskQueue.
void biogears::TaskRunner::Run | ( | ) |
Runs all tasks and waits for completion.
Member Data Documentation
|
private |
Whether or not the task runner should output percent complete as it executes.
|
mutableprivate |
Mutex used to synchronize concurrent access to the task queue.
|
private |
Queue of tasks to be run.
|
private |
Number of completed tasks.
|
private |
The number of threads to spawn when running tasks.
|
private |
Total number of tasks in the queue when the task running begins to execute.