forpy  2
forpy::threading::thread_pool Class Reference

#include <ctpl.h>

Public Member Functions

 thread_pool ()
 
 thread_pool (int nThreads)
 
 ~thread_pool ()
 
int size ()
 
int n_idle ()
 
std::thread & get_thread (int i)
 
void resize (int nThreads)
 
void clear_queue ()
 
std::function< void(INFOT)> pop ()
 
void stop (bool isWait=false)
 
template<typename C , typename F , typename M , typename... Rest>
auto push_move (F &&f, C *c, M &&movable, Rest &&... rest) -> std::future< decltype((c-> *f)(new forpy::Desk(0), movable, rest...))>
 For member functions (with parameters). More...
 
template<typename C , typename F , typename... Rest>
auto push (F &&f, C *c, Rest &&... rest) -> std::future< decltype((c-> *f)(new forpy::Desk(0), rest...))>
 For member functions (with parameters). More...
 
template<typename F , typename... Rest>
auto push (F &&f, Rest &&... rest) -> std::future< decltype(f(new forpy::Desk(0), rest...))>
 For functions with parameters. More...
 
template<typename F >
auto push (F &&f) -> std::future< decltype(f(new forpy::Desk(0)))>
 For functions without parameters. More...
 
void init ()
 

Private Member Functions

 thread_pool (const thread_pool &)=delete
 
 thread_pool (thread_pool &&)=delete
 
thread_pooloperator= (const thread_pool &)=delete
 
thread_pooloperator= (thread_pool &&)=delete
 
void set_thread (int i)
 

Private Attributes

std::vector< std::unique_ptr< std::thread > > threads
 
std::vector< std::shared_ptr< std::atomic< bool > > > flags
 
detail::Queue< std::function< void(INFOT)> * > q
 
std::atomic< bool > isDone
 
std::atomic< bool > isStop
 
std::atomic< int > nWaiting
 
std::mutex mutex
 
std::condition_variable cv
 

Detailed Description

Definition at line 75 of file ctpl.h.

Constructor & Destructor Documentation

◆ thread_pool() [1/4]

forpy::threading::thread_pool::thread_pool ( )
inline

Definition at line 77 of file ctpl.h.

◆ thread_pool() [2/4]

forpy::threading::thread_pool::thread_pool ( int  nThreads)
inline

Definition at line 78 of file ctpl.h.

◆ ~thread_pool()

forpy::threading::thread_pool::~thread_pool ( )
inline

Definition at line 84 of file ctpl.h.

◆ thread_pool() [3/4]

forpy::threading::thread_pool::thread_pool ( const thread_pool )
privatedelete

◆ thread_pool() [4/4]

forpy::threading::thread_pool::thread_pool ( thread_pool &&  )
privatedelete

Member Function Documentation

◆ clear_queue()

void forpy::threading::thread_pool::clear_queue ( )
inline

Definition at line 128 of file ctpl.h.

◆ get_thread()

std::thread& forpy::threading::thread_pool::get_thread ( int  i)
inline

Definition at line 91 of file ctpl.h.

◆ init()

void forpy::threading::thread_pool::init ( )
inline

Definition at line 235 of file ctpl.h.

◆ n_idle()

int forpy::threading::thread_pool::n_idle ( )
inline

Definition at line 90 of file ctpl.h.

◆ operator=() [1/2]

thread_pool& forpy::threading::thread_pool::operator= ( const thread_pool )
privatedelete

◆ operator=() [2/2]

thread_pool& forpy::threading::thread_pool::operator= ( thread_pool &&  )
privatedelete

◆ pop()

std::function<void(INFOT)> forpy::threading::thread_pool::pop ( )
inline

Definition at line 134 of file ctpl.h.

◆ push() [1/3]

template<typename C , typename F , typename... Rest>
auto forpy::threading::thread_pool::push ( F &&  f,
C *  c,
Rest &&...  rest 
) -> std::future<decltype((c->*f)(new forpy::Desk(0), rest...))>
inline

For member functions (with parameters).

Definition at line 194 of file ctpl.h.

◆ push() [2/3]

template<typename F , typename... Rest>
auto forpy::threading::thread_pool::push ( F &&  f,
Rest &&...  rest 
) -> std::future<decltype(f(new forpy::Desk(0), rest...))>
inline

For functions with parameters.

Definition at line 209 of file ctpl.h.

◆ push() [3/3]

template<typename F >
auto forpy::threading::thread_pool::push ( F &&  f) -> std::future<decltype(f(new forpy::Desk(0)))>
inline

For functions without parameters.

Definition at line 224 of file ctpl.h.

◆ push_move()

template<typename C , typename F , typename M , typename... Rest>
auto forpy::threading::thread_pool::push_move ( F &&  f,
C *  c,
M &&  movable,
Rest &&...  rest 
) -> std::future<decltype((c->*f)(new forpy::Desk(0), movable, rest...))>
inline

For member functions (with parameters).

Definition at line 178 of file ctpl.h.

◆ resize()

void forpy::threading::thread_pool::resize ( int  nThreads)
inline

Definition at line 97 of file ctpl.h.

◆ set_thread()

void forpy::threading::thread_pool::set_thread ( int  i)
inlineprivate

Definition at line 248 of file ctpl.h.

◆ size()

int forpy::threading::thread_pool::size ( )
inline

Definition at line 87 of file ctpl.h.

◆ stop()

void forpy::threading::thread_pool::stop ( bool  isWait = false)
inline

Definition at line 148 of file ctpl.h.

Member Data Documentation

◆ cv

std::condition_variable forpy::threading::thread_pool::cv
private

Definition at line 296 of file ctpl.h.

◆ flags

std::vector<std::shared_ptr<std::atomic<bool> > > forpy::threading::thread_pool::flags
private

Definition at line 289 of file ctpl.h.

◆ isDone

std::atomic<bool> forpy::threading::thread_pool::isDone
private

Definition at line 291 of file ctpl.h.

◆ isStop

std::atomic<bool> forpy::threading::thread_pool::isStop
private

Definition at line 292 of file ctpl.h.

◆ mutex

std::mutex forpy::threading::thread_pool::mutex
private

Definition at line 295 of file ctpl.h.

◆ nWaiting

std::atomic<int> forpy::threading::thread_pool::nWaiting
private

Definition at line 293 of file ctpl.h.

◆ q

detail::Queue<std::function<void(INFOT)> *> forpy::threading::thread_pool::q
private

Definition at line 290 of file ctpl.h.

◆ threads

std::vector<std::unique_ptr<std::thread> > forpy::threading::thread_pool::threads
private

Definition at line 288 of file ctpl.h.


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