3 #include <util/HeliosException.h>
4 #include <util/threadpool/ThreadPool.h>
21 template <
typename TaskType,
typename ThreadPoolType,
typename ... TaskArgs>
31 std::vector<shared_ptr<TaskType>>
tasks;
60 virtual inline bool add(shared_ptr<TaskType> task){
61 tasks.push_back(task);
75 virtual inline bool add(shared_ptr<TaskType> task, TaskArgs ... args){
76 tasks.push_back(task);
93 virtual inline bool add(ThreadPoolType &pool, shared_ptr<TaskType> task){
94 tasks.push_back(task);
111 virtual inline char tryAdd(ThreadPoolType &pool, shared_ptr<TaskType> task){
112 tasks.push_back(task);
128 for(shared_ptr<TaskType> task :
tasks)
doTask(*task);
139 virtual inline void drop(TaskArgs ... args){
140 for(shared_ptr<TaskType> task :
tasks)
doTask(*task, args...);
156 virtual inline void drop(ThreadPoolType &pool){
158 "TaskDropper::drop(ThreadPoolType &) cannot be used.\n"
159 "It must be overridden by any derived class providing parallel "
160 "execution through given thread pool."
171 virtual inline bool tryDrop(ThreadPoolType &pool){
173 "TaskDropper::tryDrop(ThreadPoolType &) cannot be used.\n"
174 "It must be overridden by any derived class providing parallel "
175 "non-blocking execution through given thread pool."
199 virtual inline void doTask(TaskType &task)
207 virtual inline void doTask(TaskType &task, TaskArgs ... args)
248 virtual inline shared_ptr<TaskType>
popTask(){
249 shared_ptr<TaskType> task =
tasks.back();
Base class for Helios exceptions.
Definition: HeliosException.h:12
Class which handles tasks dropping. It is, executing and then removing each task when dropping.
Definition: TaskDropper.h:22
virtual bool tryDrop(ThreadPoolType &pool)
Like drop(ThreadPoolType &) but supporting non blocking calls.
Definition: TaskDropper.h:171
virtual void drop(TaskArgs ... args)
Drop all tasks with arguments, one after another.
Definition: TaskDropper.h:139
std::vector< shared_ptr< TaskType > > tasks
Tasks to be dropped as a whole.
Definition: TaskDropper.h:31
virtual void doTask(TaskType &task)
Execute a task with no arguments.
Definition: TaskDropper.h:199
virtual void doTask(TaskType &task, TaskArgs ... args)
Execute a task with corresponding arguments.
Definition: TaskDropper.h:207
virtual bool add(shared_ptr< TaskType > task, TaskArgs ... args)
Like TaskDropper::add but for tasks with arguments.
Definition: TaskDropper.h:75
virtual char tryAdd(ThreadPoolType &pool, shared_ptr< TaskType > task)
Like TaskDropper::add(ThreadPoolType &, shared_ptr<TaskType>) but supporting non-blocking calls.
Definition: TaskDropper.h:111
virtual void drop(ThreadPoolType &pool)
A callback for TaskDropper::drop but using a thread pool to be executed in parallel.
Definition: TaskDropper.h:156
virtual bool add(ThreadPoolType &pool, shared_ptr< TaskType > task)
Like TaskDropper::add but running the drop method in parallel through a callback from given thread po...
Definition: TaskDropper.h:93
virtual size_t getMaxTasks() const
Get current maximum tasks limit.
Definition: TaskDropper.h:235
virtual void drop()
Drop all tasks, one after another.
Definition: TaskDropper.h:127
virtual void operator()(TaskArgs ... args)
Functor operator with arguments calling drop method with arguments which can be used by thread pools.
Definition: TaskDropper.h:226
virtual bool add(shared_ptr< TaskType > task)
Add a task to the TaskDropper.
Definition: TaskDropper.h:60
virtual void setMaxTasks(size_t const maxTasks)
Set new maximum tasks limit.
Definition: TaskDropper.h:242
virtual shared_ptr< TaskType > popTask()
Pop a task from vector of tasks.
Definition: TaskDropper.h:248
TaskDropper(size_t const maxTasks=32)
Default constructor for TaskDropper.
Definition: TaskDropper.h:49
size_t maxTasks
Specify the maximum number of tasks before forcing a drop.
Definition: TaskDropper.h:39
virtual void operator()()
Void functor operator calling drop method to be compatible with thread pools.
Definition: TaskDropper.h:218
TaskDropper emptyClone() const
Do an empty clone of this task dropper. It is, an exact clone but with an empty tasks vector.
Definition: TaskDropper.h:184