ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ThreadPool Class Reference

#include <thread_pool.hpp>

Classes

class  Queue
 

Public Member Functions

 ThreadPool ()
 
 ThreadPool (std::size_t num_threads)
 
 ~ThreadPool ()
 
std::size_t Size () const
 
void Resize (size_t num_threads)
 
template<typename FuncType , typename... ArgTypes>
auto Push (FuncType &&func, ArgTypes &&...args) -> std::future< decltype(func(args...))>
 

Private Member Functions

 ThreadPool (const ThreadPool &)=delete
 
ThreadPooloperator= (const ThreadPool &)=delete
 
 ThreadPool (ThreadPool &&)=delete
 
ThreadPooloperator= (ThreadPool &&)=delete
 
void DoTasksFromQueue (size_t ithread)
 
bool ReadyToAct (size_t ithread, std::unique_ptr< std::function< void()> > &task)
 

Private Attributes

Queue tasks_
 
std::vector< std::unique_ptr< std::thread > > threads_
 
std::vector< std::shared_ptr< std::atomic< bool > > > stop_thread_now_
 
std::atomic< bool > stop_at_empty_
 
std::mutex mutex_
 
std::condition_variable cv_
 

Detailed Description

Definition at line 15 of file thread_pool.hpp.

Constructor & Destructor Documentation

ThreadPool::ThreadPool ( )

Definition at line 7 of file thread_pool.cpp.

References Resize().

ThreadPool::ThreadPool ( std::size_t  num_threads)
explicit

Definition at line 24 of file thread_pool.cpp.

References Resize().

ThreadPool::~ThreadPool ( )

Definition at line 35 of file thread_pool.cpp.

References cv_, mutex_, Size(), stop_at_empty_, and threads_.

ThreadPool::ThreadPool ( const ThreadPool )
privatedelete
ThreadPool::ThreadPool ( ThreadPool &&  )
privatedelete

Member Function Documentation

void ThreadPool::DoTasksFromQueue ( size_t  ithread)
private

Definition at line 78 of file thread_pool.cpp.

References cv_, mutex_, ThreadPool::Queue::Pop(), ReadyToAct(), stop_thread_now_, and tasks_.

Referenced by Resize().

ThreadPool& ThreadPool::operator= ( const ThreadPool )
privatedelete
ThreadPool& ThreadPool::operator= ( ThreadPool &&  )
privatedelete
template<typename FuncType , typename... ArgTypes>
auto ThreadPool::Push ( FuncType &&  func,
ArgTypes &&...  args 
) -> std::future<decltype(func(args...))>
bool ThreadPool::ReadyToAct ( size_t  ithread,
std::unique_ptr< std::function< void()> > &  task 
)
private

Definition at line 93 of file thread_pool.cpp.

References ThreadPool::Queue::Pop(), stop_at_empty_, stop_thread_now_, and tasks_.

Referenced by DoTasksFromQueue().

void ThreadPool::Resize ( size_t  num_threads)

Definition at line 53 of file thread_pool.cpp.

References cv_, DoTasksFromQueue(), mutex_, Size(), stop_thread_now_, and threads_.

Referenced by ThreadPool().

size_t ThreadPool::Size ( ) const

Definition at line 49 of file thread_pool.cpp.

References threads_.

Referenced by Resize(), and ~ThreadPool().

Member Data Documentation

std::condition_variable ThreadPool::cv_
private

Definition at line 62 of file thread_pool.hpp.

Referenced by DoTasksFromQueue(), Push(), Resize(), and ~ThreadPool().

std::mutex ThreadPool::mutex_
private
std::atomic<bool> ThreadPool::stop_at_empty_
private

Definition at line 59 of file thread_pool.hpp.

Referenced by ReadyToAct(), and ~ThreadPool().

std::vector<std::shared_ptr<std::atomic<bool> > > ThreadPool::stop_thread_now_
private

Definition at line 58 of file thread_pool.hpp.

Referenced by DoTasksFromQueue(), ReadyToAct(), and Resize().

Queue ThreadPool::tasks_
private

Definition at line 56 of file thread_pool.hpp.

Referenced by DoTasksFromQueue(), Push(), and ReadyToAct().

std::vector<std::unique_ptr<std::thread> > ThreadPool::threads_
private

Definition at line 57 of file thread_pool.hpp.

Referenced by Resize(), Size(), and ~ThreadPool().


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