Helios++
Helios software for LiDAR simulations
TaskWarehouse< Task > Class Template Reference

Class implementing a warehouse to store and retrieve tasks in a thread safe fashion. More...

#include <TaskWarehouse.h>

Collaboration diagram for TaskWarehouse< Task >:

Public Member Functions

 TaskWarehouse (size_t const maxTasks=256)
 Default constructor for task warehouse.
 
virtual bool post (shared_ptr< Task > task)
 Post task into warehouse. Posted task will be stored in the warehouse only if there is enough available space. More...
 
virtual bool post (vector< shared_ptr< Task >> &_tasks)
 Post tasks into warehouse. Posted tasks will be stored in the warehouse only if there is enough available space for all of them. It is, if \(n\) tasks are posted but there is only enough space to store \(n-1\), then not even a single task will be stored. More...
 
virtual shared_ptr< Task > get ()
 Get task from warehouse, if any. Retrieved task is removed from warehouse. More...
 
virtual vector< shared_ptr< Task > > get (size_t const n)
 Get tasks from warehouse, if any. More...
 
virtual void wait ()
 Caller thread waits until notified.
 
virtual void waitIf (bool const &cond)
 Caller thread waits until notified but only if condition is satisfied (true) More...
 
virtual void notify ()
 Notify a waiting thread to stop waiting.
 
virtual void notifyAll ()
 Notify all waiting threads to stop waiting.
 
virtual void notifyUpdate (bool &flag, bool const newValue)
 Notify a waiting thread after updating flag with new value in a thread-safe way. More...
 
virtual void notifyAllUpdate (bool &flag, bool const newValue)
 Notify all waiting threads after updating flag with new value in a thread-safe way. More...
 
bool hasPendingTasks ()
 Check if there are pending tasks in the warehouse (true) or not (false) More...
 

Protected Attributes

size_t maxTasks
 Maximum number of tasks the warehouse can handle.
 
vector< shared_ptr< Task > > tasks
 Tasks handled by the warehouse.
 
boost::shared_mutex mtx
 The mutex to handle concurrent access to the tasks.
 
boost::shared_mutex wmtx
 The wait mutex to implement non-active listening waiting.
 
boost::condition_variable_any condvar
 Conditional variable to handle wait/notify signals.
 

Detailed Description

template<typename Task>
class TaskWarehouse< Task >

Class implementing a warehouse to store and retrieve tasks in a thread safe fashion.

Author
Alberto M. Esmoris Pena
Version
1.0
Template Parameters
TaskTemplate Type of tasks handled by the task warehouse

Member Function Documentation

◆ get() [1/2]

template<typename Task >
virtual shared_ptr<Task> TaskWarehouse< Task >::get ( )
inlinevirtual

Get task from warehouse, if any. Retrieved task is removed from warehouse.

Returns
Retrieved task

◆ get() [2/2]

template<typename Task >
virtual vector<shared_ptr<Task> > TaskWarehouse< Task >::get ( size_t const  n)
inlinevirtual

Get tasks from warehouse, if any.

Parameters
nHow many tasks retrieve
Returns
Retrieved tasks. If there are no tasks to retrieve, then empty vector is returned. If there are \(<n\) tasks, then as many as possible are returned

◆ hasPendingTasks()

template<typename Task >
bool TaskWarehouse< Task >::hasPendingTasks ( )
inline

Check if there are pending tasks in the warehouse (true) or not (false)

Returns
True if there are pending tasks, false otherwise

◆ notifyAllUpdate()

template<typename Task >
virtual void TaskWarehouse< Task >::notifyAllUpdate ( bool &  flag,
bool const  newValue 
)
inlinevirtual

Notify all waiting threads after updating flag with new value in a thread-safe way.

Parameters
flagFlag to be updated
newValueNew value for the flag

◆ notifyUpdate()

template<typename Task >
virtual void TaskWarehouse< Task >::notifyUpdate ( bool &  flag,
bool const  newValue 
)
inlinevirtual

Notify a waiting thread after updating flag with new value in a thread-safe way.

Parameters
flagFlag to be updated
newValueNew value for the flag

◆ post() [1/2]

template<typename Task >
virtual bool TaskWarehouse< Task >::post ( shared_ptr< Task >  task)
inlinevirtual

Post task into warehouse. Posted task will be stored in the warehouse only if there is enough available space.

Parameters
taskTask to be posted
Returns
True if task was successfully stored in warehouse, false otherwise

◆ post() [2/2]

template<typename Task >
virtual bool TaskWarehouse< Task >::post ( vector< shared_ptr< Task >> &  _tasks)
inlinevirtual

Post tasks into warehouse. Posted tasks will be stored in the warehouse only if there is enough available space for all of them. It is, if \(n\) tasks are posted but there is only enough space to store \(n-1\), then not even a single task will be stored.

Parameters
_tasksTasks to be posted
Returns
True if tasks were successfully stored in warehouse, false otherwise

◆ waitIf()

template<typename Task >
virtual void TaskWarehouse< Task >::waitIf ( bool const &  cond)
inlinevirtual

Caller thread waits until notified but only if condition is satisfied (true)

Parameters
condWait condition

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