Pol  Revision:cb584c9
Pol::threadhelp::DynTaskThreadPool Class Reference

#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< msgmsg_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
 

Detailed Description

Definition at line 98 of file threadhelp.h.

Member Typedef Documentation

typedef std::function<void()> Pol::threadhelp::DynTaskThreadPool::msg
private

Definition at line 103 of file threadhelp.h.

Constructor & Destructor Documentation

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 ( )

Member Function Documentation

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().

void Pol::threadhelp::DynTaskThreadPool::create_thread ( )
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.

Friends And Related Function Documentation

friend class PoolWorker
friend

Definition at line 100 of file threadhelp.h.

Referenced by create_thread().

Member Data Documentation

std::atomic<bool> Pol::threadhelp::DynTaskThreadPool::_done
protected
msg_queue Pol::threadhelp::DynTaskThreadPool::_msg_queue
private
std::string Pol::threadhelp::DynTaskThreadPool::_name
private

Definition at line 121 of file threadhelp.h.

Referenced by create_thread().

std::mutex Pol::threadhelp::DynTaskThreadPool::_pool_mutex
mutableprivate

Definition at line 120 of file threadhelp.h.

Referenced by create_thread(), and threadpoolsize().

std::vector<std::unique_ptr<PoolWorker> > Pol::threadhelp::DynTaskThreadPool::_threads
private

Definition at line 119 of file threadhelp.h.

Referenced by create_thread(), threadpoolsize(), and ~DynTaskThreadPool().


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