9#include "MantidKernel/DllConfig.h"
44 void push(std::shared_ptr<Task> newTask)
override {
49 std::shared_ptr<std::mutex> mut = newTask->getMutex();
50 m_supermap[mut].emplace(newTask->cost(), newTask);
54 std::shared_ptr<Task>
pop(
size_t threadnum)
override {
57 std::shared_ptr<Task> temp =
nullptr;
67 std::shared_ptr<std::mutex> mapMutex = mutexedMap.first;
77 temp = std::move(it2->second);
84 if (temp ==
nullptr) {
88 if (!mutexedMap.second.empty()) {
91 temp = std::move(map.begin()->second);
93 map.erase(map.begin());
103 std::shared_ptr<std::mutex> mut = temp->getMutex();
119 std::shared_ptr<std::mutex> mut = task->
getMutex();
131 return std::accumulate(
133 [](
size_t total,
const std::pair<
const std::shared_ptr<std::mutex> &,
const InnerMap &> &mutexedMap) {
134 return total + mutexedMap.second.size();
144 [](
const std::pair<
const std::shared_ptr<std::mutex>,
const InnerMap &> &mutexedMap) {
145 return mutexedMap.second.empty();
166 using InnerMap = std::multimap<double, std::shared_ptr<Task>>;
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
A Task is a unit of work to be scheduled and run by a ThreadPool.
std::shared_ptr< std::mutex > getMutex()
Get the mutex object for this Task.
ThreadSchedulerMutexes : Version of a ThreadSchedulerLargestCost that also makes sure to not try to s...
SuperMap m_supermap
A super map; first key = a Mutex * Inside it: second key = the cost.
std::set< std::shared_ptr< std::mutex > > m_mutexes
Vector of currently used mutexes.
ThreadSchedulerMutexes()=default
std::map< std::shared_ptr< std::mutex >, InnerMap > SuperMap
Map to maps, sorted by Mutex*.
void clear() override final
Empty out the queue.
~ThreadSchedulerMutexes() override
std::shared_ptr< Task > pop(size_t threadnum) override
Retrieves the next Task to execute.
void finished(Task *task, size_t threadnum) override
Signal to the scheduler that a task is complete.
std::multimap< double, std::shared_ptr< Task > > InnerMap
Map to tasks, sorted by cost.
void push(std::shared_ptr< Task > newTask) override
Add a Task to the queue.
size_t size() override
Returns the size of the queue.
The ThreadScheduler object defines how tasks are allocated to threads and in what order.
double m_costExecuted
Accumulated cost of tasks that have been executed (popped)
std::mutex m_queueLock
Mutex to prevent simultaneous access to the queue.
double m_cost
Total cost of all tasks.
Helper class which provides the Collimation Length for SANS instruments.