Abstract class extending basic thread pool implementation to provide a basis layer to handle thread associated resources.
More...
#include <ResThreadPool.h>
|
| ResThreadPool (std::size_t const _pool_size) |
| Resource thread pool constructor. More...
|
|
template<typename Task > |
void | run_res_task (Task task) |
| Run a task with associated resources when there is an available thread for it.
|
|
template<typename Task > |
bool | try_run_res_task (Task task) |
| Run a task with associated resources. If there is not even a single available thread, then return false so non-blocking behavior is possible. More...
|
|
| SimpleThreadPool (std::size_t const _pool_size) |
| Simple thread pool constructor. More...
|
|
void | run_task (Task task) |
| Run a task when there is an available thread for it.
|
|
virtual void | join () |
| Lock until all pending threads have finished.
|
|
virtual void | notifyOne () |
| Notify the conditional variable so if there is a waiting thread it will wake up.
|
|
| ThreadPool (std::size_t const _pool_size) |
| Thread pool constructor. More...
|
|
virtual std::size_t | getPoolSize () const |
| Obtain the thread pool size. More...
|
|
|
virtual int | getAvailableResourceSetIndex () const |
| Obtain the index of an available resource set. More...
|
|
virtual void | wrap_res_task (boost::function< void(TaskArgs ...)> &task, int const resourceIdx) |
| Wrap a task so that available threads count can be increased once provided task has been completed. More...
|
|
void | do_task (boost::function< void(TaskArgs ...)> &task) override |
| Throw exception when calling non resource do_task. More...
|
|
virtual void | do_res_task (boost::function< void(TaskArgs ...)> &task, int const resourceIdx)=0 |
| Invoke task with associated resources with corresponding arguments. More...
|
|
virtual void | wrap_task (boost::function< void(TaskArgs ...)> &task) |
| Wrap a task so that available threads count can be increased once provided task has been completed. More...
|
|
|
bool * | resourceSetAvailable |
| Array of flags specifying availability of resource sets. More...
|
|
std::size_t | available_ |
| Number of available threads, those which are not currently performing a task.
|
|
boost::mutex | mutex_ |
| Mutex to handle concurrent tasks.
|
|
boost::condition_variable | cond_ |
| Condition variable to handle tasks dispatching depending on available threads.
|
|
boost::asio::io_service | io_service_ |
| Instance of boost input/output service for asynchronous data processing.
|
|
std::size_t | pool_size |
| Size of thread pool (number of threads)
|
|
boost::asio::io_service | io_service_ |
| Instance of boost input/output service for asynchronous data processing.
|
|
boost::asio::executor_work_guard< boost::asio::io_service::executor_type > | work_ |
| Instance of work guard to report the io service when it has pending tasks. More...
|
|
std::size_t | pool_size |
| Size of thread pool (number of threads)
|
|
boost::thread_group | threads_ |
| Group of threads.
|
|
template<typename ... TaskArgs>
class ResThreadPool< TaskArgs >
Abstract class extending basic thread pool implementation to provide a basis layer to handle thread associated resources.
@verison 1.0
- See also
- ThreadPool
◆ ResThreadPool()
template<typename ... TaskArgs>
◆ do_res_task()
template<typename ... TaskArgs>
virtual void ResThreadPool< TaskArgs >::do_res_task |
( |
boost::function< void(TaskArgs ...)> & |
task, |
|
|
int const |
resourceIdx |
|
) |
| |
|
protectedpure virtual |
Invoke task with associated resources with corresponding arguments.
- Parameters
-
task | Task to be invoked |
resourceIdx | Index of resources associated with thread invoking the task |
◆ do_task()
template<typename ... TaskArgs>
void ResThreadPool< TaskArgs >::do_task |
( |
boost::function< void(TaskArgs ...)> & |
task | ) |
|
|
inlineoverrideprotectedvirtual |
◆ getAvailableResourceSetIndex()
template<typename ... TaskArgs>
virtual int ResThreadPool< TaskArgs >::getAvailableResourceSetIndex |
( |
| ) |
const |
|
inlineprotectedvirtual |
Obtain the index of an available resource set.
- Returns
- Available resource set index
◆ try_run_res_task()
template<typename ... TaskArgs>
template<typename Task >
Run a task with associated resources. If there is not even a single available thread, then return false so non-blocking behavior is possible.
- Returns
- True if task was posted for asynchronous execution. False if it was not posted because there are not enough available threads to accept it
◆ wrap_res_task()
template<typename ... TaskArgs>
virtual void ResThreadPool< TaskArgs >::wrap_res_task |
( |
boost::function< void(TaskArgs ...)> & |
task, |
|
|
int const |
resourceIdx |
|
) |
| |
|
inlineprotectedvirtual |
Wrap a task so that available threads count can be increased once provided task has been completed.
- Parameters
-
task | Task to be wrapped |
resourceIdx | Resource index associated with the task. It is necessary to release associated resources so other tasks can use them later |
◆ resourceSetAvailable
template<typename ... TaskArgs>
Array of flags specifying availability of resource sets.
The ith element of this array correspond to the ith resource for any resource set/array
The documentation for this class was generated from the following file: