MRPT
2.0.4
|
A simple thread pool.
Definition at line 29 of file WorkerThreadsPool.h.
#include <mrpt/system/WorkerThreadsPool.h>
Public Types | |
enum | queue_policy_t : uint8_t { POLICY_FIFO, POLICY_DROP_OLD } |
Public Member Functions | |
WorkerThreadsPool ()=default | |
WorkerThreadsPool (std::size_t num_threads, queue_policy_t p=POLICY_FIFO) | |
~WorkerThreadsPool () | |
void | resize (std::size_t num_threads) |
void | clear () |
Stops all working jobs. More... | |
template<class F , class... Args> | |
auto | enqueue (F &&f, Args &&... args) -> std::future< typename std::result_of< F(Args...)>::type > |
Enqueue one new working item, to be executed by threads when any is available. More... | |
std::size_t | pendingTasks () const noexcept |
Returns the number of enqueued tasks, currently waiting for a free working thread to process them. More... | |
Private Attributes | |
std::vector< std::thread > | threads_ |
std::atomic_bool | do_stop_ {false} |
std::mutex | queue_mutex_ |
std::condition_variable | condition_ |
std::queue< std::function< void()> > | tasks_ |
queue_policy_t | policy_ {POLICY_FIFO} |
enum mrpt::system::WorkerThreadsPool::queue_policy_t : uint8_t |
Enumerator | |
---|---|
POLICY_FIFO | Default policy: all tasks are executed in FIFO order. |
POLICY_DROP_OLD | If a task arrives and there are more pending tasks than worker threads, drop previous tasks. |
Definition at line 32 of file WorkerThreadsPool.h.
|
default |
|
inline |
Definition at line 42 of file WorkerThreadsPool.h.
References resize().
|
inline |
Definition at line 47 of file WorkerThreadsPool.h.
References clear().
void WorkerThreadsPool::clear | ( | ) |
Stops all working jobs.
Definition at line 18 of file WorkerThreadsPool.cpp.
References condition_, do_stop_, queue_mutex_, tasks_, and threads_.
Referenced by ~WorkerThreadsPool().
auto mrpt::system::WorkerThreadsPool::enqueue | ( | F && | f, |
Args &&... | args | ||
) | -> std::future<typename std::result_of<F(Args...)>::type> |
Enqueue one new working item, to be executed by threads when any is available.
Definition at line 71 of file WorkerThreadsPool.h.
|
noexcept |
Returns the number of enqueued tasks, currently waiting for a free working thread to process them.
Definition at line 36 of file WorkerThreadsPool.cpp.
References tasks_.
void WorkerThreadsPool::resize | ( | std::size_t | num_threads | ) |
Definition at line 41 of file WorkerThreadsPool.cpp.
References threads_.
Referenced by WorkerThreadsPool().
|
private |
Definition at line 65 of file WorkerThreadsPool.h.
Referenced by clear().
|
private |
Definition at line 63 of file WorkerThreadsPool.h.
Referenced by clear().
|
private |
Definition at line 67 of file WorkerThreadsPool.h.
|
private |
Definition at line 64 of file WorkerThreadsPool.h.
Referenced by clear().
|
private |
Definition at line 66 of file WorkerThreadsPool.h.
Referenced by clear(), and pendingTasks().
|
private |
Definition at line 62 of file WorkerThreadsPool.h.
Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020 |