Kea  1.9.9-git
isc::util::MultiThreadingMgr Class Reference

Multi Threading Manager. More...

#include <multi_threading_mgr.h>

+ Inheritance diagram for isc::util::MultiThreadingMgr:

Public Member Functions

void addCriticalSectionCallbacks (const std::string &name, const CSCallbackPair::Callback &entry_cb, const CSCallbackPair::Callback &exit_cb)
 Adds a pair of callbacks to the list of CriticalSection callbacks. More...
 
void apply (bool enabled, uint32_t thread_count, uint32_t queue_size)
 Apply the multi-threading related settings. More...
 
void enterCriticalSection ()
 Enter critical section. More...
 
void exitCriticalSection ()
 Exit critical section. More...
 
bool getMode () const
 Get the multi-threading mode. More...
 
uint32_t getPacketQueueSize ()
 Get the configured dhcp packet queue size. More...
 
ThreadPool< std::function< void()> > & getThreadPool ()
 Get the dhcp thread pool. More...
 
uint32_t getThreadPoolSize () const
 Get the configured dhcp thread pool size. More...
 
bool isInCriticalSection ()
 Is in critical section flag. More...
 
void removeAllCriticalSectionCallbacks ()
 Removes all callbacks in the list of CriticalSection callbacks. More...
 
void removeCriticalSectionCallbacks (const std::string &name)
 Removes the set of callbacks associated with a given name from the list of CriticalSection callbacks. More...
 
void setMode (bool enabled)
 Set the multi-threading mode. More...
 
void setPacketQueueSize (uint32_t size)
 Set the configured dhcp packet queue size. More...
 
void setThreadPoolSize (uint32_t size)
 Set the configured dhcp thread pool size. More...
 

Static Public Member Functions

static uint32_t detectThreadCount ()
 The system current detected hardware concurrency thread count. More...
 
static MultiThreadingMgrinstance ()
 Returns a single instance of Multi Threading Manager. More...
 

Protected Member Functions

 MultiThreadingMgr ()
 Constructor. More...
 
virtual ~MultiThreadingMgr ()
 Destructor. More...
 

Detailed Description

Multi Threading Manager.

This singleton class holds the multi-threading mode.

The standard way to use it is:

multi-threaded code
} else {
single-threaded code
}

For instance for a class protected by its mutex:

namespace locked {
void foo() { ... }
} // end of locked namespace
void foo() {
lock_guard<mutex> lock(mutex_);
locked::foo();
} else {
locked::foo();
}
}

Definition at line 120 of file multi_threading_mgr.h.

Constructor & Destructor Documentation

isc::util::MultiThreadingMgr::MultiThreadingMgr ( )
protected

Constructor.

Definition at line 14 of file multi_threading_mgr.cc.

isc::util::MultiThreadingMgr::~MultiThreadingMgr ( )
protectedvirtual

Destructor.

Definition at line 18 of file multi_threading_mgr.cc.

Member Function Documentation

void isc::util::MultiThreadingMgr::addCriticalSectionCallbacks ( const std::string &  name,
const CSCallbackPair::Callback entry_cb,
const CSCallbackPair::Callback exit_cb 
)

Adds a pair of callbacks to the list of CriticalSection callbacks.

Note
Callbacks must be exception-safe, handling any errors themselves.
Parameters
nameName of the set of callbacks. This value is used by the callback owner to add and remove them. Duplicates are not allowed.
entry_cbCallback to invoke upon CriticalSection entry. Cannot be empty.
exit_cbCallback to invoke upon CriticalSection exit. Cannot be empty.

Definition at line 160 of file multi_threading_mgr.cc.

References isc::util::CSCallbackPairList::addCallbackPair().

+ Here is the call graph for this function:

void isc::util::MultiThreadingMgr::apply ( bool  enabled,
uint32_t  thread_count,
uint32_t  queue_size 
)

Apply the multi-threading related settings.

Parameters
enabledThe enabled flag: true if multi-threading is enabled, false otherwise.
thread_countThe desired number of threads: non 0 if explicitly configured, 0 if auto scaling is desired
queue_sizeThe desired thread queue size: non 0 if explicitly configured, 0 for unlimited size

Definition at line 88 of file multi_threading_mgr.cc.

References detectThreadCount(), isInCriticalSection(), removeAllCriticalSectionCallbacks(), isc::util::ThreadPool< WorkItem, Container >::reset(), setMode(), setPacketQueueSize(), setThreadPoolSize(), isc::util::ThreadPool< WorkItem, Container >::size(), isc::util::ThreadPool< WorkItem, Container >::start(), and isc::util::ThreadPool< WorkItem, Container >::stop().

+ Here is the call graph for this function:

uint32_t isc::util::MultiThreadingMgr::detectThreadCount ( )
static

The system current detected hardware concurrency thread count.

This function will return 0 if the value can not be determined.

Returns
The thread count.

Definition at line 83 of file multi_threading_mgr.cc.

Referenced by apply().

void isc::util::MultiThreadingMgr::enterCriticalSection ( )

Enter critical section.

When entering MultiThreadingCriticalSection, increment internal counter so that any configuration change that might start the packet thread pool is delayed until exiting the respective section. If the internal counter is 0, then stop the thread pool.

Definition at line 38 of file multi_threading_mgr.cc.

Referenced by isc::util::MultiThreadingCriticalSection::MultiThreadingCriticalSection().

void isc::util::MultiThreadingMgr::exitCriticalSection ( )

Exit critical section.

When exiting MultiThreadingCriticalSection, decrement internal counter so that the dhcp thread pool can be started according to the new configuration. If the internal counter is 0, then start the thread pool.

Definition at line 44 of file multi_threading_mgr.cc.

References isc_throw.

Referenced by isc::util::MultiThreadingCriticalSection::~MultiThreadingCriticalSection().

bool isc::util::MultiThreadingMgr::getMode ( ) const

Get the multi-threading mode.

Returns
The current multi-threading mode: true if multi-threading is enabled, false otherwise.

Definition at line 28 of file multi_threading_mgr.cc.

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

uint32_t isc::util::MultiThreadingMgr::getPacketQueueSize ( )

Get the configured dhcp packet queue size.

Returns
The dhcp packet queue size.

Definition at line 73 of file multi_threading_mgr.cc.

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

+ Here is the call graph for this function:

ThreadPool< std::function< void()> > & isc::util::MultiThreadingMgr::getThreadPool ( )

Get the dhcp thread pool.

Returns
The dhcp thread pool.

Definition at line 58 of file multi_threading_mgr.cc.

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

uint32_t isc::util::MultiThreadingMgr::getThreadPoolSize ( ) const

Get the configured dhcp thread pool size.

Returns
The dhcp thread pool size.

Definition at line 63 of file multi_threading_mgr.cc.

bool isc::util::MultiThreadingMgr::isInCriticalSection ( )

Is in critical section flag.

Returns
The critical section flag.

Definition at line 53 of file multi_threading_mgr.cc.

Referenced by apply().

void isc::util::MultiThreadingMgr::removeAllCriticalSectionCallbacks ( )

Removes all callbacks in the list of CriticalSection callbacks.

Definition at line 172 of file multi_threading_mgr.cc.

References isc::util::CSCallbackPairList::removeAll().

Referenced by apply().

+ Here is the call graph for this function:

void isc::util::MultiThreadingMgr::removeCriticalSectionCallbacks ( const std::string &  name)

Removes the set of callbacks associated with a given name from the list of CriticalSection callbacks.

If the name is not found in the list, it simply returns, otherwise both callbacks registered under the name are removed.

Parameters
nameName of the set of callbacks to remove.

Definition at line 167 of file multi_threading_mgr.cc.

References isc::util::CSCallbackPairList::removeCallbackPair().

+ Here is the call graph for this function:

void isc::util::MultiThreadingMgr::setMode ( bool  enabled)

Set the multi-threading mode.

Parameters
enabledThe new mode.

Definition at line 33 of file multi_threading_mgr.cc.

Referenced by apply(), isc::test::MultiThreadingTest::MultiThreadingTest(), and isc::test::MultiThreadingTest::~MultiThreadingTest().

void isc::util::MultiThreadingMgr::setPacketQueueSize ( uint32_t  size)

Set the configured dhcp packet queue size.

Parameters
sizeThe dhcp packet queue size.

Definition at line 78 of file multi_threading_mgr.cc.

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

Referenced by apply().

+ Here is the call graph for this function:

void isc::util::MultiThreadingMgr::setThreadPoolSize ( uint32_t  size)

Set the configured dhcp thread pool size.

Parameters
sizeThe dhcp thread pool size.

Definition at line 68 of file multi_threading_mgr.cc.

Referenced by apply().


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