Kea
1.9.9-git
|
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... | |
Defines a thread pool which uses a thread pool queue for managing work items.
Each work item is a 'functor' object.
WorkItem | a functor |
Container | a 'queue like' container |
Definition at line 34 of file thread_pool.h.
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.
|
inline |
Constructor.
Definition at line 48 of file thread_pool.h.
|
inline |
Destructor.
Definition at line 52 of file thread_pool.h.
|
inline |
add a work item to the thread pool
item | the 'functor' object to be added to the queue |
Definition at line 97 of file thread_pool.h.
|
inline |
add a work item to the thread pool at front
item | the 'functor' object to be added to the queue |
Definition at line 105 of file thread_pool.h.
Referenced by isc::dhcp::ClientHandler::~ClientHandler().
|
inline |
count number of work items in the queue
Definition at line 112 of file thread_pool.h.
|
inline |
get maximum number of work items in the queue
Definition at line 153 of file thread_pool.h.
Referenced by isc::util::MultiThreadingMgr::getPacketQueueSize().
|
inline |
get queue length statistic
which | select the statistic (10, 100 or 1000) |
InvalidParameter | if which is not 10 and 100 and 1000. |
Definition at line 169 of file thread_pool.h.
|
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().
|
inline |
set maximum number of work items in the queue
max_queue_size | the maximum size (0 means unlimited) |
Definition at line 146 of file thread_pool.h.
Referenced by isc::util::MultiThreadingMgr::setPacketQueueSize().
|
inline |
size number of thread pool threads
Definition at line 160 of file thread_pool.h.
Referenced by isc::util::MultiThreadingMgr::apply().
|
inline |
start all the threads
thread_count | specifies the number of threads to be created and started |
InvalidOperation | if thread pool already started |
InvalidParameter | if thread count is 0 |
Definition at line 72 of file thread_pool.h.
Referenced by isc::util::MultiThreadingMgr::apply().
|
inline |
stop all the threads
InvalidOperation | if thread pool already stopped |
Definition at line 85 of file thread_pool.h.
Referenced by isc::util::MultiThreadingMgr::apply().
|
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.
|
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
seconds | the time in seconds to wait for tasks to finish |
Definition at line 135 of file thread_pool.h.
|
static |
Rounding value for 10 packet statistic.
Initialize the 10 packet rounding to exp(-.1)
Definition at line 36 of file thread_pool.h.
|
static |
Rounding value for 100 packet statistic.
Initialize the 100 packet rounding to exp(-.01)
Definition at line 39 of file thread_pool.h.
|
static |
Rounding value for 1000 packet statistic.
Initialize the 1000 packet rounding to exp(-.001)
Definition at line 42 of file thread_pool.h.