Kea
1.9.9-git
|
Multi Threading Manager. More...
#include <multi_threading_mgr.h>
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 MultiThreadingMgr & | instance () |
Returns a single instance of Multi Threading Manager. More... | |
Protected Member Functions | |
MultiThreadingMgr () | |
Constructor. More... | |
virtual | ~MultiThreadingMgr () |
Destructor. More... | |
Multi Threading Manager.
This singleton class holds the multi-threading mode.
The standard way to use it is:
For instance for a class protected by its mutex:
Definition at line 120 of file multi_threading_mgr.h.
|
protected |
Constructor.
Definition at line 14 of file multi_threading_mgr.cc.
|
protectedvirtual |
Destructor.
Definition at line 18 of file multi_threading_mgr.cc.
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.
name | Name of the set of callbacks. This value is used by the callback owner to add and remove them. Duplicates are not allowed. |
entry_cb | Callback to invoke upon CriticalSection entry. Cannot be empty. |
exit_cb | Callback to invoke upon CriticalSection exit. Cannot be empty. |
Definition at line 160 of file multi_threading_mgr.cc.
References isc::util::CSCallbackPairList::addCallbackPair().
void isc::util::MultiThreadingMgr::apply | ( | bool | enabled, |
uint32_t | thread_count, | ||
uint32_t | queue_size | ||
) |
Apply the multi-threading related settings.
enabled | The enabled flag: true if multi-threading is enabled, false otherwise. |
thread_count | The desired number of threads: non 0 if explicitly configured, 0 if auto scaling is desired |
queue_size | The 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().
|
static |
The system current detected hardware concurrency thread count.
This function will return 0 if the value can not be determined.
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.
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.
Definition at line 73 of file multi_threading_mgr.cc.
References isc::util::ThreadPool< WorkItem, Container >::getMaxQueueSize().
ThreadPool< std::function< void()> > & isc::util::MultiThreadingMgr::getThreadPool | ( | ) |
Get 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.
Definition at line 63 of file multi_threading_mgr.cc.
|
static |
Returns a single instance of Multi Threading Manager.
MultiThreadingMgr is a singleton and this method is the only way of accessing it.
Definition at line 22 of file multi_threading_mgr.cc.
Referenced by isc::dhcp_ddns::NameChangeSender::assumeQueue(), isc::hooks::LibraryManager::checkMultiThreadingCompatible(), isc::ha::LeaseUpdateBacklog::clear(), isc::dhcp_ddns::NameChangeSender::clearSendQueue(), isc::dhcp_ddns::NameChangeSender::getQueueSize(), isc::dhcp_ddns::NameChangeSender::invokeSendHandler(), isc::dhcp_ddns::NameChangeSender::isSendInProgress(), isc::util::MultiThreadingCriticalSection::MultiThreadingCriticalSection(), isc::test::MultiThreadingTest::MultiThreadingTest(), isc::dhcp_ddns::NameChangeSender::peekAt(), isc::dhcp::AllocEngine::Allocator::pickAddress(), isc::ha::LeaseUpdateBacklog::pop(), isc::ha::LeaseUpdateBacklog::push(), isc::dhcp_ddns::NameChangeSender::sendRequest(), isc::http::HttpConnectionPool::shutdown(), isc::ha::LeaseUpdateBacklog::size(), isc::dhcp_ddns::NameChangeSender::skipNext(), isc::http::HttpConnectionPool::start(), isc::dhcp_ddns::NameChangeSender::startSending(), isc::http::HttpConnectionPool::stop(), isc::http::HttpConnectionPool::stopAll(), isc::ha::LeaseUpdateBacklog::wasOverflown(), isc::util::MultiThreadingCriticalSection::~MultiThreadingCriticalSection(), and isc::test::MultiThreadingTest::~MultiThreadingTest().
bool isc::util::MultiThreadingMgr::isInCriticalSection | ( | ) |
Is in 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().
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.
name | Name of the set of callbacks to remove. |
Definition at line 167 of file multi_threading_mgr.cc.
References isc::util::CSCallbackPairList::removeCallbackPair().
void isc::util::MultiThreadingMgr::setMode | ( | bool | enabled | ) |
Set the multi-threading mode.
enabled | The 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.
size | The dhcp packet queue size. |
Definition at line 78 of file multi_threading_mgr.cc.
References isc::util::ThreadPool< WorkItem, Container >::setMaxQueueSize().
Referenced by apply().
void isc::util::MultiThreadingMgr::setThreadPoolSize | ( | uint32_t | size | ) |
Set the configured dhcp thread pool size.
size | The dhcp thread pool size. |
Definition at line 68 of file multi_threading_mgr.cc.
Referenced by apply().