|
Pol
Revision:cb584c9
|
#include <threadhelp.h>
Inheritance diagram for Pol::threadhelp::DynTaskThreadPool:Classes | |
| class | PoolWorker |
Public Member Functions | |
| DynTaskThreadPool (const std::string &name) | |
| Creates a dynamic threadpool of workers. if no idle worker is found creates a new worker thread blocks on deconstruction eg: DynTaskThreadPool workers; for (....) workers.push([&](){dosomework();});. More... | |
| ~DynTaskThreadPool () | |
| std::future< bool > | checked_push (const msg &msg) |
| returns a future which will be set once the msg is processed More... | |
| void | push (const msg &msg) |
| simply fire and forget only the deconstructor ensures the msg to be finished More... | |
| size_t | threadpoolsize () const |
Protected Attributes | |
| std::atomic< bool > | _done |
Private Types | |
| typedef std::function< void()> | msg |
| typedef Clib::message_queue< msg > | msg_queue |
Private Member Functions | |
| void | create_thread () |
Private Attributes | |
| msg_queue | _msg_queue |
| std::string | _name |
| std::mutex | _pool_mutex |
| std::vector< std::unique_ptr< PoolWorker > > | _threads |
Friends | |
| class | PoolWorker |
Definition at line 98 of file threadhelp.h.
|
private |
Definition at line 103 of file threadhelp.h.
|
private |
Definition at line 104 of file threadhelp.h.
| Pol::threadhelp::DynTaskThreadPool::DynTaskThreadPool | ( | const std::string & | name | ) |
Creates a dynamic threadpool of workers. if no idle worker is found creates a new worker thread blocks on deconstruction eg: DynTaskThreadPool workers; for (....) workers.push([&](){dosomework();});.
Definition at line 505 of file threadhelp.cpp.
| Pol::threadhelp::DynTaskThreadPool::~DynTaskThreadPool | ( | ) |
Definition at line 531 of file threadhelp.cpp.
References _done, _msg_queue, _threads, Pol::Clib::message_queue< Message >::cancel(), and Pol::Clib::message_queue< Message >::push().
| std::future< bool > Pol::threadhelp::DynTaskThreadPool::checked_push | ( | const msg & | msg | ) |
returns a future which will be set once the msg is processed
Definition at line 550 of file threadhelp.cpp.
References _msg_queue, create_thread(), and Pol::Clib::message_queue< Message >::push().
|
private |
Definition at line 516 of file threadhelp.cpp.
References _name, _pool_mutex, _threads, ERROR_PRINT, and PoolWorker.
Referenced by checked_push(), and push().
| void Pol::threadhelp::DynTaskThreadPool::push | ( | const msg & | msg | ) |
simply fire and forget only the deconstructor ensures the msg to be finished
Definition at line 543 of file threadhelp.cpp.
References _msg_queue, create_thread(), and Pol::Clib::message_queue< Message >::push().
| size_t Pol::threadhelp::DynTaskThreadPool::threadpoolsize | ( | ) | const |
Definition at line 510 of file threadhelp.cpp.
References _pool_mutex, and _threads.
|
friend |
Definition at line 100 of file threadhelp.h.
Referenced by create_thread().
|
protected |
Definition at line 114 of file threadhelp.h.
Referenced by Pol::threadhelp::DynTaskThreadPool::PoolWorker::run(), and ~DynTaskThreadPool().
|
private |
Definition at line 118 of file threadhelp.h.
Referenced by checked_push(), push(), Pol::threadhelp::DynTaskThreadPool::PoolWorker::run(), and ~DynTaskThreadPool().
|
private |
Definition at line 121 of file threadhelp.h.
Referenced by create_thread().
|
mutableprivate |
Definition at line 120 of file threadhelp.h.
Referenced by create_thread(), and threadpoolsize().
|
private |
Definition at line 119 of file threadhelp.h.
Referenced by create_thread(), threadpoolsize(), and ~DynTaskThreadPool().