Mantid
Loading...
Searching...
No Matches
Task.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9#ifndef Q_MOC_RUN
10#include <memory>
11#endif
12#include "MantidKernel/DllConfig.h"
14#include <mutex>
15
16namespace Mantid {
17
18namespace Kernel {
19
20//==============================================================================================
29class MANTID_KERNEL_DLL Task {
30public:
31 //---------------------------------------------------------------------------------------------
33 Task() : m_cost(1.0) {}
34
35 //---------------------------------------------------------------------------------------------
40 Task(double cost) : m_cost(cost) {}
41
43 virtual ~Task() = default;
44
45 //---------------------------------------------------------------------------------------------
47 virtual void run() = 0;
48
49 //---------------------------------------------------------------------------------------------
53 virtual double cost() { return m_cost; }
54
55 //---------------------------------------------------------------------------------------------
63 void setMutexObject(void *object) {
64 UNUSED_ARG(object);
66 }
67
68 //---------------------------------------------------------------------------------------------
72 std::shared_ptr<std::mutex> getMutex() { return m_mutex; }
73
74 //---------------------------------------------------------------------------------------------
78 void setMutex(const std::shared_ptr<std::mutex> &mutex) { m_mutex = mutex; }
79
80protected:
82 double m_cost;
83
85 std::shared_ptr<std::mutex> m_mutex;
86};
87
88} // namespace Kernel
89} // namespace Mantid
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
Marks code as not implemented yet.
Definition: Exception.h:138
A Task is a unit of work to be scheduled and run by a ThreadPool.
Definition: Task.h:29
Task()
Default constructor.
Definition: Task.h:33
virtual double cost()
What is the computational cost of this task?
Definition: Task.h:53
std::shared_ptr< std::mutex > m_mutex
Mutex associated with this task (can be NULL)
Definition: Task.h:85
virtual ~Task()=default
Destructor.
void setMutexObject(void *object)
Use an arbitrary pointer to lock (mutex) the execution of this task.
Definition: Task.h:63
double m_cost
Cached computational cost for the thread.
Definition: Task.h:82
void setMutex(const std::shared_ptr< std::mutex > &mutex)
Set the mutex object for this Task.
Definition: Task.h:78
std::shared_ptr< std::mutex > getMutex()
Get the mutex object for this Task.
Definition: Task.h:72
virtual void run()=0
Main method that performs the work for the task.
Task(double cost)
Constructor with cost.
Definition: Task.h:40
Helper class which provides the Collimation Length for SANS instruments.