OpenJPH
Open-source implementation of JPEG2000 Part-15
|
Implements a pool of threads, and can queue tasks. More...
#include <ojph_threads.h>
Public Member Functions | |
thread_pool () | |
default constructor More... | |
~thread_pool () | |
default destructor More... | |
void | init (size_t num_threads) |
Initializes the thread pool. More... | |
void | add_task (worker_thread_base *task) |
Adds a task to the thread pool. More... | |
size_t | get_num_threads () |
Returns the number of threads in the thread pool. More... | |
Static Private Member Functions | |
static void | start_thread (thread_pool *tp) |
A static function to start a thread. More... | |
Private Attributes | |
std::vector< std::thread > | threads |
std::deque< worker_thread_base * > | tasks |
std::mutex | mutex |
std::condition_variable | condition |
std::atomic_bool | stop |
Implements a pool of threads, and can queue tasks.
Definition at line 97 of file ojph_threads.h.
|
inline |
ojph::thds::thread_pool::~thread_pool | ( | ) |
default destructor
Definition at line 54 of file ojph_threads.cpp.
void ojph::thds::thread_pool::add_task | ( | worker_thread_base * | task | ) |
Adds a task to the thread pool.
task | the task to added, must be derived from worker_thread_base |
Definition at line 73 of file ojph_threads.cpp.
References condition, mutex, and tasks.
Referenced by ojph::stex::frames_handler::send_to_processing().
|
inline |
Returns the number of threads in the thread pool.
@retuen number of threads in the thread pool
Definition at line 129 of file ojph_threads.h.
References threads.
Referenced by ojph::stex::frames_handler::init().
void ojph::thds::thread_pool::init | ( | size_t | num_threads | ) |
Initializes the thread pool.
num_threads | the number of threads the thread pool holds |
Definition at line 63 of file ojph_threads.cpp.
References start_thread(), and threads.
Referenced by main().
|
staticprivate |
A static function to start a thread.
tp | a pointer to the thread pool |
Definition at line 82 of file ojph_threads.cpp.
References condition, ojph::thds::worker_thread_base::execute(), mutex, stop, and tasks.
Referenced by init().
|
private |
Definition at line 143 of file ojph_threads.h.
Referenced by add_task(), start_thread(), and ~thread_pool().
|
private |
Definition at line 142 of file ojph_threads.h.
Referenced by add_task(), and start_thread().
|
private |
Definition at line 144 of file ojph_threads.h.
Referenced by start_thread(), thread_pool(), and ~thread_pool().
|
private |
Definition at line 141 of file ojph_threads.h.
Referenced by add_task(), and start_thread().
|
private |
Definition at line 140 of file ojph_threads.h.
Referenced by get_num_threads(), init(), and ~thread_pool().