Kea 2.7.6
isc::asiolink::IoServiceThreadPool Class Reference

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.
 

Detailed Description

Implements a pausable pool of IOService driven threads.

Definition at line 24 of file io_service_thread_pool.h.

Member Enumeration Documentation

◆ State

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.

Constructor & Destructor Documentation

◆ IoServiceThreadPool()

IoServiceThreadPool::IoServiceThreadPool ( asiolink::IOServicePtr io_service,
size_t pool_size,
bool defer_start = false )

Constructor.

Parameters
io_serviceIOService that will drive the pool's IO. If empty, it create its own instance.
pool_sizeMaximum number of threads in the pool. Currently the number of threads is fixed at this value.
defer_startIf 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().

+ Here is the call graph for this function:

◆ ~IoServiceThreadPool()

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

+ Here is the call graph for this function:

Member Function Documentation

◆ checkPausePermissions()

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.

Exceptions
MultiThreadingInvalidOperationif the state transition is done on any of the worker threads.

Definition at line 102 of file io_service_thread_pool.cc.

References PAUSED.

◆ getIOService()

IOServicePtr IoServiceThreadPool::getIOService ( ) const

Fetches the IOService that drives the pool.

Returns
the pointer to the IOService.

Definition at line 279 of file io_service_thread_pool.cc.

◆ getPoolSize()

uint16_t IoServiceThreadPool::getPoolSize ( ) const

Fetches the maximum size of the thread pool.

Returns
the maximum size of the thread pool.

Definition at line 284 of file io_service_thread_pool.cc.

◆ getThreadCount()

uint16_t IoServiceThreadPool::getThreadCount ( ) const

Fetches the number of threads in the pool.

Returns
the number of running threads.

Definition at line 289 of file io_service_thread_pool.cc.

◆ isPaused()

bool isc::asiolink::IoServiceThreadPool::isPaused ( )
inline

Check if the thread pool is paused.

Returns
True if the thread pool is paused, false otherwise.

Definition at line 84 of file io_service_thread_pool.h.

References PAUSED.

◆ isRunning()

bool isc::asiolink::IoServiceThreadPool::isRunning ( )
inline

Check if the thread pool is running.

Returns
True if the thread pool is running, false otherwise.

Definition at line 77 of file io_service_thread_pool.h.

References RUNNING.

◆ isStopped()

bool isc::asiolink::IoServiceThreadPool::isStopped ( )
inline

Check if the thread pool is stopped.

Returns
True if the thread pool is stopped, false otherwise.

Definition at line 91 of file io_service_thread_pool.h.

References STOPPED.

◆ pause()

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.

◆ run()

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

◆ stop()

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


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