Class implementing a warehouse to store and retrieve tasks in a thread safe fashion.
More...
#include <TaskWarehouse.h>
|
| 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...
|
|
|
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.
|
|
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
-
Task | Template Type of tasks handled by the task warehouse |
◆ get() [1/2]
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
-
- 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()
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
-
flag | Flag to be updated |
newValue | New 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
-
flag | Flag to be updated |
newValue | New 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
-
- 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
-
- Returns
- True if tasks were successfully stored in warehouse, false otherwise
◆ waitIf()
Caller thread waits until notified but only if condition is satisfied (true)
- Parameters
-
The documentation for this class was generated from the following file: