Kea  1.9.9-git
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. More...
 

Public Member Functions

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

Static Public Attributes

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

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

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

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.

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.

Member Function Documentation

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.

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.

Referenced by isc::dhcp::ClientHandler::~ClientHandler().

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.

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 153 of file thread_pool.h.

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

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 169 of file thread_pool.h.

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::MultiThreadingMgr::apply(), and isc::util::ThreadPool< std::function< void()> >::~ThreadPool().

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 146 of file thread_pool.h.

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

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 160 of file thread_pool.h.

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

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.

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

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.

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

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.

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.

Member Data Documentation

template<typename WorkItem, typename Container = std::deque<boost::shared_ptr<WorkItem>>>
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.

template<typename WorkItem, typename Container = std::deque<boost::shared_ptr<WorkItem>>>
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.

template<typename WorkItem, typename Container = std::deque<boost::shared_ptr<WorkItem>>>
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: