Kea 2.7.5
isc::util::ThreadPool< WorkItem, Container > Struct Template Reference

Defines a thread pool which uses a thread pool queue for managing work items. More...

#include <thread_pool.h>

Public Types

typedef boost::shared_ptr< WorkItem > WorkItemPtr
 Type of shared pointers to work items.
 

Public Member Functions

 ThreadPool ()
 Constructor.
 
 ~ThreadPool ()
 Destructor.
 
bool add (const WorkItemPtr &item)
 add a work item to the thread pool
 
bool addFront (const WorkItemPtr &item)
 add a work item to the thread pool at front
 
size_t count ()
 count number of work items in the queue
 
bool enabled ()
 return the enable state of the queue
 
size_t getMaxQueueSize ()
 get maximum number of work items in the queue
 
double getQueueStat (size_t which)
 get queue length statistic
 
void pause (bool wait=true)
 pause threads
 
bool paused ()
 return the pause state of the queue
 
void reset ()
 reset the thread pool stopping threads and clearing the internal queue
 
void resume ()
 resume threads
 
void setMaxQueueSize (size_t max_queue_size)
 set maximum number of work items in the queue
 
size_t size ()
 size number of thread pool threads
 
void start (uint32_t thread_count)
 start all the threads
 
void stop ()
 stop all the threads
 
void wait ()
 wait for current items to be processed
 
bool wait (uint32_t seconds)
 wait for items to be processed or return after timeout
 

Static Public Attributes

static const double CEXP10 = std::exp(-.1)
 Rounding value for 10 packet statistic.
 
static const double CEXP100 = std::exp(-.01)
 Rounding value for 100 packet statistic.
 
static const double CEXP1000 = std::exp(-.001)
 Rounding value for 1000 packet statistic.
 

Detailed Description

template<typename WorkItem, typename Container = std::deque<boost::shared_ptr<WorkItem>>>
struct isc::util::ThreadPool< WorkItem, Container >

Defines a thread pool which uses a thread pool queue for managing work items.

Each work item is a 'functor' object.

Template Parameters
WorkItema functor
Containera 'queue like' container

Definition at line 34 of file thread_pool.h.

Member Typedef Documentation

◆ WorkItemPtr

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
typedef boost::shared_ptr<WorkItem> isc::util::ThreadPool< WorkItem, Container >::WorkItemPtr

Type of shared pointers to work items.

Definition at line 45 of file thread_pool.h.

Constructor & Destructor Documentation

◆ ThreadPool()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
isc::util::ThreadPool< WorkItem, Container >::ThreadPool ( )
inline

Constructor.

Definition at line 48 of file thread_pool.h.

◆ ~ThreadPool()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
isc::util::ThreadPool< WorkItem, Container >::~ThreadPool ( )
inline

Destructor.

Definition at line 52 of file thread_pool.h.

References isc::util::ThreadPool< WorkItem, Container >::reset().

+ Here is the call graph for this function:

Member Function Documentation

◆ add()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
bool isc::util::ThreadPool< WorkItem, Container >::add ( const WorkItemPtr & item)
inline

add a work item to the thread pool

Parameters
itemthe 'functor' object to be added to the queue
Returns
false if the queue was full and oldest item(s) was dropped, true otherwise.

Definition at line 97 of file thread_pool.h.

◆ addFront()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
bool isc::util::ThreadPool< WorkItem, Container >::addFront ( const WorkItemPtr & item)
inline

add a work item to the thread pool at front

Parameters
itemthe 'functor' object to be added to the queue
Returns
false if the queue was full, true otherwise.

Definition at line 105 of file thread_pool.h.

◆ count()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
size_t isc::util::ThreadPool< WorkItem, Container >::count ( )
inline

count number of work items in the queue

Returns
the number of work items in the queue

Definition at line 112 of file thread_pool.h.

◆ enabled()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
bool isc::util::ThreadPool< WorkItem, Container >::enabled ( )
inline

return the enable state of the queue

The 'enabled' state corresponds to true value The 'disabled' state corresponds to false value

Returns
the enable state of the queue

Definition at line 165 of file thread_pool.h.

Referenced by isc::util::MultiThreadingMgr::exitCriticalSection().

◆ getMaxQueueSize()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
size_t isc::util::ThreadPool< WorkItem, Container >::getMaxQueueSize ( )
inline

get maximum number of work items in the queue

Returns
the maximum size (0 means unlimited)

Definition at line 189 of file thread_pool.h.

Referenced by isc::util::MultiThreadingMgr::getPacketQueueSize().

◆ getQueueStat()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
double isc::util::ThreadPool< WorkItem, Container >::getQueueStat ( size_t which)
inline

get queue length statistic

Parameters
whichselect the statistic (10, 100 or 1000)
Returns
the queue length statistic
Exceptions
InvalidParameterif which is not 10 and 100 and 1000.

Definition at line 205 of file thread_pool.h.

◆ pause()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
void isc::util::ThreadPool< WorkItem, Container >::pause ( bool wait = true)
inline

pause threads

Used to pause threads so that they stop processing tasks

Parameters
waitthe flag indicating if should wait for threads to pause.

Definition at line 148 of file thread_pool.h.

References isc::util::ThreadPool< WorkItem, Container >::wait().

Referenced by isc::util::MultiThreadingMgr::enterCriticalSection().

+ Here is the call graph for this function:

◆ paused()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
bool isc::util::ThreadPool< WorkItem, Container >::paused ( )
inline

return the pause state of the queue

The 'paused' state corresponds to true value The 'resumed' state corresponds to false value

Returns
the pause state of the queue

Definition at line 175 of file thread_pool.h.

◆ reset()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
void isc::util::ThreadPool< WorkItem, Container >::reset ( )
inline

reset the thread pool stopping threads and clearing the internal queue

It can be called several times even when the thread pool is stopped

Definition at line 60 of file thread_pool.h.

Referenced by isc::util::ThreadPool< WorkItem, Container >::~ThreadPool(), and isc::util::MultiThreadingMgr::apply().

◆ resume()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
void isc::util::ThreadPool< WorkItem, Container >::resume ( )
inline

resume threads

Used to resume threads so that they start processing tasks

Definition at line 155 of file thread_pool.h.

Referenced by isc::util::MultiThreadingMgr::exitCriticalSection().

◆ setMaxQueueSize()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
void isc::util::ThreadPool< WorkItem, Container >::setMaxQueueSize ( size_t max_queue_size)
inline

set maximum number of work items in the queue

Parameters
max_queue_sizethe maximum size (0 means unlimited)

Definition at line 182 of file thread_pool.h.

Referenced by isc::util::MultiThreadingMgr::setPacketQueueSize().

◆ size()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
size_t isc::util::ThreadPool< WorkItem, Container >::size ( )
inline

size number of thread pool threads

Returns
the number of threads

Definition at line 196 of file thread_pool.h.

Referenced by isc::util::MultiThreadingMgr::apply().

◆ start()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
void isc::util::ThreadPool< WorkItem, Container >::start ( uint32_t thread_count)
inline

start all the threads

Parameters
thread_countspecifies the number of threads to be created and started
Exceptions
InvalidOperationif thread pool already started
InvalidParameterif thread count is 0

Definition at line 72 of file thread_pool.h.

References isc_throw.

Referenced by isc::util::MultiThreadingMgr::apply(), and isc::util::MultiThreadingMgr::exitCriticalSection().

◆ stop()

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
void isc::util::ThreadPool< WorkItem, Container >::stop ( )
inline

stop all the threads

Exceptions
InvalidOperationif thread pool already stopped

Definition at line 85 of file thread_pool.h.

References isc_throw.

Referenced by isc::util::MultiThreadingMgr::apply().

◆ wait() [1/2]

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
void isc::util::ThreadPool< WorkItem, Container >::wait ( )
inline

wait for current items to be processed

Used to block the calling thread until all items in the queue have been processed

Definition at line 120 of file thread_pool.h.

References isc_throw.

Referenced by isc::util::ThreadPool< WorkItem, Container >::pause().

◆ wait() [2/2]

template<typename WorkItem , typename Container = std::deque<boost::shared_ptr<WorkItem>>>
bool isc::util::ThreadPool< WorkItem, Container >::wait ( uint32_t seconds)
inline

wait for items to be processed or return after timeout

Used to block the calling thread until all items in the queue have been processed or return after timeout

Parameters
secondsthe time in seconds to wait for tasks to finish
Returns
true if all tasks finished, false on timeout

Definition at line 135 of file thread_pool.h.

References isc_throw.

Member Data Documentation

◆ CEXP10

template<typename W , typename C >
const double isc::util::ThreadPool< W, C >::CEXP10 = std::exp(-.1)
static

Rounding value for 10 packet statistic.

Initialize the 10 packet rounding to exp(-.1)

Definition at line 36 of file thread_pool.h.

◆ CEXP100

template<typename W , typename C >
const double isc::util::ThreadPool< W, C >::CEXP100 = std::exp(-.01)
static

Rounding value for 100 packet statistic.

Initialize the 100 packet rounding to exp(-.01)

Definition at line 39 of file thread_pool.h.

◆ CEXP1000

template<typename W , typename C >
const double isc::util::ThreadPool< W, C >::CEXP1000 = std::exp(-.001)
static

Rounding value for 1000 packet statistic.

Initialize the 1000 packet rounding to exp(-.001)

Definition at line 42 of file thread_pool.h.


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