Helios++
Helios software for LiDAR simulations
TaskDropper< TaskType, ThreadPoolType, TaskArgs > Class Template Reference

Class which handles tasks dropping. It is, executing and then removing each task when dropping. More...

#include <TaskDropper.h>

Inheritance diagram for TaskDropper< TaskType, ThreadPoolType, TaskArgs >:
Collaboration diagram for TaskDropper< TaskType, ThreadPoolType, TaskArgs >:

Public Member Functions

 TaskDropper (size_t const maxTasks=32)
 Default constructor for TaskDropper. More...
 
virtual bool add (shared_ptr< TaskType > task)
 Add a task to the TaskDropper. More...
 
virtual bool add (shared_ptr< TaskType > task, TaskArgs ... args)
 Like TaskDropper::add but for tasks with arguments. More...
 
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 pool. More...
 
virtual char tryAdd (ThreadPoolType &pool, shared_ptr< TaskType > task)
 Like TaskDropper::add(ThreadPoolType &, shared_ptr<TaskType>) but supporting non-blocking calls. More...
 
virtual void drop ()
 Drop all tasks, one after another. More...
 
virtual void drop (TaskArgs ... args)
 Drop all tasks with arguments, one after another. More...
 
virtual void drop (ThreadPoolType &pool)
 A callback for TaskDropper::drop but using a thread pool to be executed in parallel. More...
 
virtual bool tryDrop (ThreadPoolType &pool)
 Like drop(ThreadPoolType &) but supporting non blocking calls. More...
 
TaskDropper emptyClone () const
 Do an empty clone of this task dropper. It is, an exact clone but with an empty tasks vector. More...
 
virtual void operator() ()
 Void functor operator calling drop method to be compatible with thread pools. More...
 
virtual void operator() (TaskArgs ... args)
 Functor operator with arguments calling drop method with arguments which can be used by thread pools. More...
 
virtual size_t getMaxTasks () const
 Get current maximum tasks limit. More...
 
virtual void setMaxTasks (size_t const maxTasks)
 Set new maximum tasks limit. More...
 
virtual shared_ptr< TaskType > popTask ()
 Pop a task from vector of tasks. More...
 

Protected Member Functions

virtual void doTask (TaskType &task)
 Execute a task with no arguments. More...
 
virtual void doTask (TaskType &task, TaskArgs ... args)
 Execute a task with corresponding arguments. More...
 

Protected Attributes

std::vector< shared_ptr< TaskType > > tasks
 Tasks to be dropped as a whole. More...
 
size_t maxTasks
 Specify the maximum number of tasks before forcing a drop. More...
 

Detailed Description

template<typename TaskType, typename ThreadPoolType, typename ... TaskArgs>
class TaskDropper< TaskType, ThreadPoolType, TaskArgs >

Class which handles tasks dropping. It is, executing and then removing each task when dropping.

Author
Alberto M. Esmoris Pena
Version
1.0
Template Parameters
TaskTypeType of task handled by the task dropper
TaskArgsArguments for the functor of the task handled by the task dropper

Constructor & Destructor Documentation

◆ TaskDropper()

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
TaskDropper< TaskType, ThreadPoolType, TaskArgs >::TaskDropper ( size_t const  maxTasks = 32)
inline

Default constructor for TaskDropper.

Parameters
maxTasksValue to initialize maximum tasks limit
See also
TaskDropper::maxTasks

Member Function Documentation

◆ add() [1/3]

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual bool TaskDropper< TaskType, ThreadPoolType, TaskArgs >::add ( shared_ptr< TaskType >  task)
inlinevirtual

Add a task to the TaskDropper.

Parameters
taskTask to be added
Returns
True if dropper has dropped its tasks, false otherwise

◆ add() [2/3]

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual bool TaskDropper< TaskType, ThreadPoolType, TaskArgs >::add ( shared_ptr< TaskType >  task,
TaskArgs ...  args 
)
inlinevirtual

Like TaskDropper::add but for tasks with arguments.

Parameters
argsArguments as common input for each task. They will be used just in case maxTasks limit has been reached
Returns
True if dropper has dropped its tasks, false otherwise
See also
TaskDropper::add

◆ add() [3/3]

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual bool TaskDropper< TaskType, ThreadPoolType, TaskArgs >::add ( ThreadPoolType &  pool,
shared_ptr< TaskType >  task 
)
inlinevirtual

Like TaskDropper::add but running the drop method in parallel through a callback from given thread pool.

Parameters
poolThread pool to be used to do the the drop method callback in parallel
Returns
True if dropper has dropped its tasks, false otherwise
See also
TaskDropper::add
TaskDropper::drop(ThreadPoolType &)
ThreadPool

◆ doTask() [1/2]

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual void TaskDropper< TaskType, ThreadPoolType, TaskArgs >::doTask ( TaskType &  task)
inlineprotectedvirtual

Execute a task with no arguments.

For implementations handling tasks that mandatory require arguments it is recommended to override this method to throw an exception

Parameters
taskTask to be executed

◆ doTask() [2/2]

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual void TaskDropper< TaskType, ThreadPoolType, TaskArgs >::doTask ( TaskType &  task,
TaskArgs ...  args 
)
inlineprotectedvirtual

Execute a task with corresponding arguments.

Parameters
taskTask to be executed
argsArguments for the task to be executed

◆ drop() [1/3]

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual void TaskDropper< TaskType, ThreadPoolType, TaskArgs >::drop ( )
inlinevirtual

Drop all tasks, one after another.

Dropped tasks will be executed and then released from tasks vector. Notwithstanding, at least for this default implementation, tasks will not be removed from tasks vector until all have been executed

◆ drop() [2/3]

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual void TaskDropper< TaskType, ThreadPoolType, TaskArgs >::drop ( TaskArgs ...  args)
inlinevirtual

Drop all tasks with arguments, one after another.

This method works like TaskDropper::drop but for tasks with arguments

Parameters
argsArguments for the task to be executed
See also
TaskDropper::drop

◆ drop() [3/3]

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual void TaskDropper< TaskType, ThreadPoolType, TaskArgs >::drop ( ThreadPoolType &  pool)
inlinevirtual

A callback for TaskDropper::drop but using a thread pool to be executed in parallel.

The callback TaskDropper::drop will be called through functor operator, with or without arguments depending on the thread pool implementation

Parameters
poolThread pool to be used for parallel execution
See also
TaskDropper::drop
TaskDropper::add(ThreadPoolType &, shared_ptr<TaskType>)
ThreadPool
TaskDropper::tryDrop(ThreadPoolType &)

◆ emptyClone()

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
TaskDropper TaskDropper< TaskType, ThreadPoolType, TaskArgs >::emptyClone ( ) const
inline

Do an empty clone of this task dropper. It is, an exact clone but with an empty tasks vector.

Returns
Empty clone of this task dropper

◆ getMaxTasks()

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual size_t TaskDropper< TaskType, ThreadPoolType, TaskArgs >::getMaxTasks ( ) const
inlinevirtual

Get current maximum tasks limit.

Returns
Current maximum tasks limit
See also
TaskDropper::maxTasks

◆ operator()() [1/2]

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual void TaskDropper< TaskType, ThreadPoolType, TaskArgs >::operator() ( )
inlinevirtual

Void functor operator calling drop method to be compatible with thread pools.

See also
TaskDropper::drop

◆ operator()() [2/2]

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual void TaskDropper< TaskType, ThreadPoolType, TaskArgs >::operator() ( TaskArgs ...  args)
inlinevirtual

Functor operator with arguments calling drop method with arguments which can be used by thread pools.

Parameters
argsArguments for tasks to be executed (the same arguments for each task)
See also
TaskDRopper::drop

◆ popTask()

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual shared_ptr<TaskType> TaskDropper< TaskType, ThreadPoolType, TaskArgs >::popTask ( )
inlinevirtual

Pop a task from vector of tasks.

Returns
Popped task from vector of tasks

◆ setMaxTasks()

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual void TaskDropper< TaskType, ThreadPoolType, TaskArgs >::setMaxTasks ( size_t const  maxTasks)
inlinevirtual

Set new maximum tasks limit.

Parameters
maxTasksNew maximum tasks limit
See also
TaskDropper::maxTasks

◆ tryAdd()

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual char TaskDropper< TaskType, ThreadPoolType, TaskArgs >::tryAdd ( ThreadPoolType &  pool,
shared_ptr< TaskType >  task 
)
inlinevirtual

Like TaskDropper::add(ThreadPoolType &, shared_ptr<TaskType>) but supporting non-blocking calls.

Returns
0 if no drop was necessary, 1 if drop was necessary and successfully posted to the thread pool, 2 if drop was necessary but was rejected by thread pool in a non-blocking fashion
See also
TaskDropper::add(ThreadPoolType &, shared_ptr<TaskType>)
TaskDropper::tryDrop(ThreadPoolType &)

◆ tryDrop()

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual bool TaskDropper< TaskType, ThreadPoolType, TaskArgs >::tryDrop ( ThreadPoolType &  pool)
inlinevirtual

Like drop(ThreadPoolType &) but supporting non blocking calls.

Returns
True if the task was successfully posted to the thread pool, false if it was rejected in a non-blocking fashion
See also
TaskDropper::drop(ThreadPoolType &)
TaskDropper::tryAdd(ThreadPoolType &, shared_ptr<TaskType>)

Member Data Documentation

◆ maxTasks

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
size_t TaskDropper< TaskType, ThreadPoolType, TaskArgs >::maxTasks
protected

Specify the maximum number of tasks before forcing a drop.

If it is \(m=0\), then forcing a drop will never happen. If it is \(m>0\), then forcing a drop will happen as soon as \(\vert\vec{T}\vert = m\) is satisfied

◆ tasks

template<typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
std::vector<shared_ptr<TaskType> > TaskDropper< TaskType, ThreadPoolType, TaskArgs >::tasks
protected

Tasks to be dropped as a whole.

Task vector is denoted in the documentation as \(\vec{T}\)


The documentation for this class was generated from the following file: