|
Mantid
|
The ThreadScheduler object defines how tasks are allocated to threads and in what order. More...
#include <ThreadScheduler.h>
Public Member Functions | |
| virtual void | abort (std::runtime_error exception) |
| Signal to the scheduler that a task is complete. | |
| virtual void | clear ()=0 |
| Empty out the queue. | |
| virtual bool | empty ()=0 |
| Returns true if the queue is empty. | |
| virtual void | finished (Task *task, size_t threadnum) |
| Signal to the scheduler that a task is complete. | |
| bool | getAborted () |
| Returns true if the execution was aborted. | |
| std::runtime_error | getAbortException () |
| Returns the exception that was caught, if any. | |
| bool | hasBusyThreads () const |
| Returns true if any thread is busy. | |
| void | markBusy () |
| Mark a thread as busy. | |
| void | markIdle () |
| Mark a thread as no longer busy. See markBusy(). | |
| virtual std::shared_ptr< Task > | pop (size_t threadnum)=0 |
| Retrieves the next Task to execute. | |
| virtual void | push (std::shared_ptr< Task > newTask)=0 |
| Add a Task to the queue. | |
| virtual size_t | size ()=0 |
| Returns the size of the queue. | |
| ThreadScheduler () | |
| Constructor. | |
| double | totalCost () |
| Returns the total cost of all Task's in the queue. | |
| double | totalCostExecuted () |
| Returns the total cost of all Task's in the queue. | |
| virtual | ~ThreadScheduler ()=default |
| Destructor. | |
Protected Attributes | |
| bool | m_aborted |
| The run was aborted due to an exception. | |
| std::runtime_error | m_abortException |
| The exception that aborted the run. | |
| double | m_cost |
| Total cost of all tasks. | |
| double | m_costExecuted |
| Accumulated cost of tasks that have been executed (popped) | |
| std::atomic< size_t > | m_numBusyThreads {0} |
| Number of threads that are getting or running a task. | |
| std::mutex | m_queueLock |
| Mutex to prevent simultaneous access to the queue. | |
The ThreadScheduler object defines how tasks are allocated to threads and in what order.
It holds the queue of tasks.
Definition at line 33 of file ThreadScheduler.h.
|
inline |
Constructor.
Definition at line 37 of file ThreadScheduler.h.
|
virtualdefault |
Destructor.
|
inlinevirtual |
Signal to the scheduler that a task is complete.
The scheduler may release mutexes, etc.
| exception | :: the exception that aborted the run. |
Definition at line 72 of file ThreadScheduler.h.
Referenced by Mantid::Kernel::ThreadPoolRunnable::run().
|
pure virtual |
Empty out the queue.
Implemented in Mantid::Kernel::ThreadSchedulerFIFO, Mantid::Kernel::ThreadSchedulerLargestCost, and Mantid::Kernel::ThreadSchedulerMutexes.
|
pure virtual |
Returns true if the queue is empty.
Implemented in Mantid::Kernel::ThreadSchedulerFIFO, Mantid::Kernel::ThreadSchedulerLargestCost, and Mantid::Kernel::ThreadSchedulerMutexes.
Referenced by Mantid::Kernel::ThreadPoolRunnable::run().
|
inlinevirtual |
Signal to the scheduler that a task is complete.
| task | :: the Task that was completed. |
| threadnum | :: Thread ID that launched the task |
Reimplemented in Mantid::Kernel::ThreadSchedulerMutexes.
Definition at line 61 of file ThreadScheduler.h.
References UNUSED_ARG.
Referenced by Mantid::Kernel::ThreadPoolRunnable::run().
|
inline |
Returns true if the execution was aborted.
Definition at line 103 of file ThreadScheduler.h.
|
inline |
Returns the exception that was caught, if any.
Definition at line 100 of file ThreadScheduler.h.
|
inline |
Returns true if any thread is busy.
A running task may still add tasks to the queue, so threads should not exit while this is true.
Definition at line 117 of file ThreadScheduler.h.
Referenced by Mantid::Kernel::ThreadPoolRunnable::run().
|
inline |
Mark a thread as busy.
A thread calls this before asking for a task and calls markIdle() once it has none, or once the task it got has finished.
Definition at line 109 of file ThreadScheduler.h.
|
inline |
Mark a thread as no longer busy. See markBusy().
Definition at line 112 of file ThreadScheduler.h.
|
pure virtual |
Retrieves the next Task to execute.
| threadnum | :: ID of the calling thread. |
Implemented in Mantid::Kernel::ThreadSchedulerFIFO, Mantid::Kernel::ThreadSchedulerLIFO, Mantid::Kernel::ThreadSchedulerLargestCost, and Mantid::Kernel::ThreadSchedulerMutexes.
Referenced by Mantid::Kernel::ThreadPoolRunnable::run().
|
pure virtual |
Add a Task to the queue.
| newTask | :: Task to add to queue |
Implemented in Mantid::Kernel::ThreadSchedulerFIFO, Mantid::Kernel::ThreadSchedulerLargestCost, and Mantid::Kernel::ThreadSchedulerMutexes.
Referenced by Mantid::DataHandling::LoadBankFromDiskTask::run().
|
pure virtual |
Returns the size of the queue.
Implemented in Mantid::Kernel::ThreadSchedulerFIFO, Mantid::Kernel::ThreadSchedulerLargestCost, and Mantid::Kernel::ThreadSchedulerMutexes.
Referenced by Mantid::MDAlgorithms::MinusMD::doMinus(), Mantid::MDAlgorithms::PlusMD::doPlus(), and Mantid::MDAlgorithms::ConvertToDiffractionMDWorkspace::exec().
|
inline |
Returns the total cost of all Task's in the queue.
Definition at line 92 of file ThreadScheduler.h.
|
inline |
Returns the total cost of all Task's in the queue.
Definition at line 96 of file ThreadScheduler.h.
|
protected |
The run was aborted due to an exception.
Definition at line 129 of file ThreadScheduler.h.
|
protected |
The exception that aborted the run.
Definition at line 127 of file ThreadScheduler.h.
|
protected |
Total cost of all tasks.
Definition at line 121 of file ThreadScheduler.h.
Referenced by Mantid::Kernel::ThreadSchedulerMutexes::clear(), and Mantid::Kernel::ThreadSchedulerMutexes::push().
|
protected |
Accumulated cost of tasks that have been executed (popped)
Definition at line 123 of file ThreadScheduler.h.
Referenced by Mantid::Kernel::ThreadSchedulerMutexes::clear().
|
protected |
Number of threads that are getting or running a task.
Definition at line 131 of file ThreadScheduler.h.
|
protected |
Mutex to prevent simultaneous access to the queue.
Definition at line 125 of file ThreadScheduler.h.
Referenced by Mantid::Kernel::ThreadSchedulerMutexes::clear(), Mantid::Kernel::ThreadSchedulerMutexes::empty(), Mantid::Kernel::ThreadSchedulerMutexes::finished(), Mantid::Kernel::ThreadSchedulerMutexes::pop(), Mantid::Kernel::ThreadSchedulerMutexes::push(), and Mantid::Kernel::ThreadSchedulerMutexes::size().