Kea 2.7.6
|
Implements a pausable pool of IOService driven threads. More...
#include <io_service_thread_pool.h>
Public Types | |
enum class | State { STOPPED , RUNNING , PAUSED } |
Describes the possible operational state of the thread pool. More... | |
Public Member Functions | |
IoServiceThreadPool (asiolink::IOServicePtr io_service, size_t pool_size, bool defer_start=false) | |
Constructor. | |
~IoServiceThreadPool () | |
Destructor. | |
void | checkPausePermissions () |
Check current thread permissions to transition to the new PAUSED state. | |
asiolink::IOServicePtr | getIOService () const |
Fetches the IOService that drives the pool. | |
uint16_t | getPoolSize () const |
Fetches the maximum size of the thread pool. | |
uint16_t | getThreadCount () const |
Fetches the number of threads in the pool. | |
bool | isPaused () |
Check if the thread pool is paused. | |
bool | isRunning () |
Check if the thread pool is running. | |
bool | isStopped () |
Check if the thread pool is stopped. | |
void | pause () |
Transitions the pool from RUNNING to PAUSED. | |
void | run () |
Transitions the pool from STOPPED or PAUSED to RUNNING. | |
void | stop () |
Transitions the pool from RUNNING or PAUSED to STOPPED. | |
Implements a pausable pool of IOService driven threads.
Definition at line 24 of file io_service_thread_pool.h.
|
strong |
Describes the possible operational state of the thread pool.
Enumerator | |
---|---|
STOPPED | |
RUNNING | Pool is not operational. |
PAUSED | Pool is populated with running threads. |
Definition at line 27 of file io_service_thread_pool.h.
IoServiceThreadPool::IoServiceThreadPool | ( | asiolink::IOServicePtr | io_service, |
size_t | pool_size, | ||
bool | defer_start = false ) |
Constructor.
io_service | IOService that will drive the pool's IO. If empty, it create its own instance. |
pool_size | Maximum number of threads in the pool. Currently the number of threads is fixed at this value. |
defer_start | If true, creation of the threads is deferred until a subsequent call to run(). In this case the pool's operational state post construction is STOPPED. If false, the constructor will invoke run() to transition the pool into the RUNNING state. |
Definition at line 30 of file io_service_thread_pool.cc.
References isc_throw, and run().
IoServiceThreadPool::~IoServiceThreadPool | ( | ) |
Destructor.
Ensures the thread pool is stopped prior to destruction.
Definition at line 50 of file io_service_thread_pool.cc.
References stop().
void IoServiceThreadPool::checkPausePermissions | ( | ) |
Check current thread permissions to transition to the new PAUSED state.
This function throws MultiThreadingInvalidOperation if the calling thread is one of the worker threads. This would prevent a dead-lock if the calling thread would try to perform a thread pool state transition to PAUSED state.
MultiThreadingInvalidOperation | if the state transition is done on any of the worker threads. |
Definition at line 102 of file io_service_thread_pool.cc.
References PAUSED.
IOServicePtr IoServiceThreadPool::getIOService | ( | ) | const |
Fetches the IOService that drives the pool.
Definition at line 279 of file io_service_thread_pool.cc.
uint16_t IoServiceThreadPool::getPoolSize | ( | ) | const |
Fetches the maximum size of the thread pool.
Definition at line 284 of file io_service_thread_pool.cc.
uint16_t IoServiceThreadPool::getThreadCount | ( | ) | const |
Fetches the number of threads in the pool.
Definition at line 289 of file io_service_thread_pool.cc.
|
inline |
Check if the thread pool is paused.
Definition at line 84 of file io_service_thread_pool.h.
References PAUSED.
|
inline |
Check if the thread pool is running.
Definition at line 77 of file io_service_thread_pool.h.
References RUNNING.
|
inline |
Check if the thread pool is stopped.
Definition at line 91 of file io_service_thread_pool.h.
References STOPPED.
void IoServiceThreadPool::pause | ( | ) |
Transitions the pool from RUNNING to PAUSED.
Pool threads suspend event processing and pause until they are released to either resume running or stop. Has no effect if the pool is already in the PAUSED or STOPPED state.
Definition at line 60 of file io_service_thread_pool.cc.
References PAUSED.
void IoServiceThreadPool::run | ( | ) |
Transitions the pool from STOPPED or PAUSED to RUNNING.
When called from the STOPPED state, the pool threads are created and begin processing events. When called from the PAUSED state, the pool threads are released from PAUSED and resume processing events. Has no effect if the pool is already in the RUNNING state.
Definition at line 55 of file io_service_thread_pool.cc.
References RUNNING.
Referenced by IoServiceThreadPool().
void IoServiceThreadPool::stop | ( | ) |
Transitions the pool from RUNNING or PAUSED to STOPPED.
Stops thread event processing and then destroys the pool's threads Has no effect if the pool is already in the STOPPED state.
Definition at line 65 of file io_service_thread_pool.cc.
References STOPPED.
Referenced by ~IoServiceThreadPool().