Kea 2.7.6
|
Multi Threading Manager. More...
#include <multi_threading_mgr.h>
Public Member Functions | |
void | addCriticalSectionCallbacks (const std::string &name, const CSCallbackSet::Callback &check_cb, const CSCallbackSet::Callback &entry_cb, const CSCallbackSet::Callback &exit_cb) |
Adds a set of callbacks to the list of CriticalSection callbacks. | |
void | apply (bool enabled, uint32_t thread_count, uint32_t queue_size) |
Apply the multi-threading related settings. | |
void | enterCriticalSection () |
Enter critical section. | |
void | exitCriticalSection () |
Exit critical section. | |
bool | getMode () const |
Get the multi-threading mode. | |
uint32_t | getPacketQueueSize () |
Get the configured dhcp packet queue size. | |
ThreadPool< std::function< void()> > & | getThreadPool () |
Get the dhcp thread pool. | |
uint32_t | getThreadPoolSize () const |
Get the configured dhcp thread pool size. | |
bool | isInCriticalSection () |
Is in critical section flag. | |
bool | isTestMode () const |
Checks if the MultiThreadingMgr is in the test mode. | |
void | removeAllCriticalSectionCallbacks () |
Removes all callbacks in the list of CriticalSection callbacks. | |
void | removeCriticalSectionCallbacks (const std::string &name) |
Removes the set of callbacks associated with a given name from the list of CriticalSection callbacks. | |
void | setMode (bool enabled) |
Set the multi-threading mode. | |
void | setPacketQueueSize (uint32_t size) |
Set the configured dhcp packet queue size. | |
void | setTestMode (const bool test_mode) |
Sets or clears the test mode for MultiThreadingMgr . | |
void | setThreadPoolSize (uint32_t size) |
Set the configured dhcp thread pool size. | |
Static Public Member Functions | |
static uint32_t | detectThreadCount () |
The system current detected hardware concurrency thread count. | |
static MultiThreadingMgr & | instance () |
Returns a single instance of Multi Threading Manager. | |
Protected Member Functions | |
MultiThreadingMgr () | |
Constructor. | |
virtual | ~MultiThreadingMgr () |
Destructor. | |
Multi Threading Manager.
This singleton class holds the multi-threading mode.
See the MultiThreadingLock class for a standard way of protecting code with a mutex. Or if you want to make it look like you're writing more code:
For instance for a class protected by its mutex:
Definition at line 136 of file multi_threading_mgr.h.
|
protected |
Constructor.
Definition at line 16 of file multi_threading_mgr.cc.
|
protectedvirtual |
Destructor.
Definition at line 21 of file multi_threading_mgr.cc.
void isc::util::MultiThreadingMgr::addCriticalSectionCallbacks | ( | const std::string & | name, |
const CSCallbackSet::Callback & | check_cb, | ||
const CSCallbackSet::Callback & | entry_cb, | ||
const CSCallbackSet::Callback & | exit_cb ) |
Adds a set 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. |
check_cb | Callback to check current thread permissions to call the CriticalSection entry and exit callbacks. |
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 216 of file multi_threading_mgr.cc.
References isc::util::CSCallbackSetList::addCallbackSet().
Referenced by isc::ha::HAService::startClientAndListener().
void isc::util::MultiThreadingMgr::apply | ( | bool | enabled, |
uint32_t | thread_count, | ||
uint32_t | queue_size ) |
Apply the multi-threading related settings.
This function should usually be called after constructing a MultiThreadingCriticalSection so that all thread pool parameters can be safely applied.
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 124 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().
Referenced by isc::dhcp::ControlledDhcpv4Srv::~ControlledDhcpv4Srv(), isc::dhcp::ControlledDhcpv6Srv::~ControlledDhcpv6Srv(), isc::dhcp::CfgMultiThreading::apply(), isc::dhcp::configureDhcp4Server(), isc::dhcp::configureDhcp6Server(), isc::dhcp::Dhcpv4Srv::run(), and isc::dhcp::Dhcpv6Srv::run().
|
static |
The system current detected hardware concurrency thread count.
This function will return 0 if the value can not be determined.
Definition at line 119 of file multi_threading_mgr.cc.
Referenced by apply(), and isc::ha::HAConfig::validate().
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.
Invokes all CriticalSection entry callbacks. Has no effect in single-threaded mode.
Definition at line 41 of file multi_threading_mgr.cc.
References getMode(), getThreadPoolSize(), isInCriticalSection(), and isc::util::ThreadPool< WorkItem, Container >::pause().
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.
Invokes all CriticalSection exit callbacks. Has no effect in single-threaded mode.
Definition at line 60 of file multi_threading_mgr.cc.
References isc::util::ThreadPool< WorkItem, Container >::enabled(), getMode(), getThreadPoolSize(), isc_throw, isInCriticalSection(), isc::util::ThreadPool< WorkItem, Container >::resume(), and isc::util::ThreadPool< WorkItem, Container >::start().
Referenced by isc::util::MultiThreadingCriticalSection::~MultiThreadingCriticalSection().
bool isc::util::MultiThreadingMgr::getMode | ( | ) | const |
Get the multi-threading mode.
Definition at line 31 of file multi_threading_mgr.cc.
Referenced by isc::dhcp::ClientHandler::~ClientHandler(), enterCriticalSection(), and exitCriticalSection().
uint32_t isc::util::MultiThreadingMgr::getPacketQueueSize | ( | ) |
Get the configured dhcp packet queue size.
Definition at line 109 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 94 of file multi_threading_mgr.cc.
Referenced by isc::dhcp::ClientHandler::~ClientHandler(), isc::dhcp::Dhcpv4Srv::processLocalizedQuery4(), isc::dhcp::Dhcpv6Srv::processLocalizedQuery6(), isc::dhcp::Dhcpv4Srv::selectSubnet(), isc::dhcp::Dhcpv6Srv::selectSubnet(), and isc::dhcp::Dhcpv4Srv::selectSubnet4o6().
uint32_t isc::util::MultiThreadingMgr::getThreadPoolSize | ( | ) | const |
Get the configured dhcp thread pool size.
Definition at line 99 of file multi_threading_mgr.cc.
Referenced by enterCriticalSection(), and exitCriticalSection().
|
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 25 of file multi_threading_mgr.cc.
Referenced by isc::util::MultiThreadingCriticalSection::MultiThreadingCriticalSection(), isc::util::MultiThreadingLock::MultiThreadingLock(), isc::test::MultiThreadingTest::MultiThreadingTest(), isc::dhcp::ClientHandler::~ClientHandler(), isc::dhcp::ControlledDhcpv4Srv::~ControlledDhcpv4Srv(), isc::dhcp::ControlledDhcpv6Srv::~ControlledDhcpv6Srv(), isc::util::MultiThreadingCriticalSection::~MultiThreadingCriticalSection(), isc::test::MultiThreadingTest::~MultiThreadingTest(), isc::dhcp::Memfile_LeaseMgr::addLease(), isc::dhcp::Memfile_LeaseMgr::addLease(), isc::ha::QueryFilter::amServingScope(), isc::ha::CommunicationState4::analyzeMessage(), isc::ha::CommunicationState6::analyzeMessage(), isc::dhcp::CfgMultiThreading::apply(), isc::dhcp_ddns::NameChangeSender::assumeQueue(), isc::dhcp::TimerMgrImpl::cancel(), isc::ha::LeaseUpdateBacklog::clear(), isc::ha::CommunicationState::clearRejectedLeaseUpdates(), isc::dhcp_ddns::NameChangeSender::clearSendQueue(), isc::ha::CommunicationState::clockSkewShouldTerminate(), isc::ha::CommunicationState::clockSkewShouldWarn(), isc::dhcp::configureDhcp4Server(), isc::dhcp::configureDhcp6Server(), isc::dhcp::Memfile_LeaseMgr::deleteExpiredReclaimedLeases4(), isc::dhcp::Memfile_LeaseMgr::deleteExpiredReclaimedLeases6(), isc::dhcp::Memfile_LeaseMgr::deleteLease(), isc::dhcp::Memfile_LeaseMgr::deleteLease(), isc::ha::CommunicationState4::failureDetected(), isc::ha::CommunicationState6::failureDetected(), isc::dhcp::Memfile_LeaseMgr::getClassLeaseCount(), isc::ha::CommunicationState4::getConnectingClientsCount(), isc::ha::CommunicationState6::getConnectingClientsCount(), isc::ha::CommunicationState::getDurationInMillisecs(), isc::ha::CommunicationState::getDurationSincePartnerStateTime(), isc::dhcp::Memfile_LeaseMgr::getExpiredLeases4(), isc::dhcp::Memfile_LeaseMgr::getExpiredLeases6(), isc::dhcp::IfaceCollection::getIface(), isc::dhcp::IfaceCollection::getIface(), isc::dhcp::Memfile_LeaseMgr::getLease4(), isc::dhcp::Memfile_LeaseMgr::getLease4(), isc::dhcp::Memfile_LeaseMgr::getLease4(), isc::dhcp::Memfile_LeaseMgr::getLease4(), isc::dhcp::Memfile_LeaseMgr::getLease4(), isc::dhcp::Memfile_LeaseMgr::getLease6(), isc::dhcp::Memfile_LeaseMgr::getLeases4(), isc::dhcp::Memfile_LeaseMgr::getLeases4(), isc::dhcp::Memfile_LeaseMgr::getLeases4(), isc::dhcp::Memfile_LeaseMgr::getLeases4(), isc::dhcp::Memfile_LeaseMgr::getLeases4ByRelayId(), isc::dhcp::Memfile_LeaseMgr::getLeases4ByRemoteId(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::Memfile_LeaseMgr::getLeases6ByRelayId(), isc::dhcp::Memfile_LeaseMgr::getLeases6ByRemoteId(), isc::ha::CommunicationState::getPartnerScopes(), isc::ha::CommunicationState::getPartnerState(), isc::ha::HAService::getPendingRequest(), isc::dhcp_ddns::NameChangeSender::getQueueSize(), isc::ha::CommunicationState::getRejectedLeaseUpdatesCount(), isc::ha::QueryFilter::getServedScopes(), isc::ha::CommunicationState4::getUnackedClientsCount(), isc::ha::CommunicationState6::getUnackedClientsCount(), isc::ha::CommunicationState::getUnsentUpdateCount(), isc::ha::CommunicationState::hasPartnerNewUnsentUpdates(), isc::ha::CommunicationState::increaseUnsentUpdateCount(), isc::ha::QueryFilter::inScope(), isc::ha::QueryFilter::inScope(), isc::dhcp_ddns::NameChangeSender::invokeSendHandler(), isc::ha::CommunicationState::isHeartbeatRunning(), isc::dhcp_ddns::NameChangeSender::isSendInProgress(), isc::dhcp::TimerMgrImpl::isTimerRegistered(), isc::lease_cmds::LeaseCmdsImpl::lease4UpdateHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6BulkApplyHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6UpdateHandler(), isc::lease_cmds::LeaseCmdsImpl::leaseAddHandler(), isc::ha::HAService::leaseUpdateComplete(), isc::dhcp::ControlledDhcpv4Srv::loadConfigFile(), isc::dhcp::ControlledDhcpv6Srv::loadConfigFile(), isc::ha::CommunicationState::logFormatClockSkew(), isc::ha::CommunicationState::modifyPokeTime(), isc::dhcp_ddns::NameChangeSender::peekAt(), isc::ha::HAService::pendingRequestSize(), isc::ha::CommunicationState::poke(), isc::ha::LeaseUpdateBacklog::pop(), isc::dhcp::Dhcpv4Srv::processDhcp4Query(), isc::dhcp::Dhcpv6Srv::processDhcp6Query(), isc::dhcp::Dhcpv4Srv::processDiscover(), isc::dhcp::Dhcpv4Srv::processLocalizedQuery4(), isc::dhcp::Dhcpv6Srv::processLocalizedQuery6(), isc::dhcp::Dhcpv6Srv::processRebind(), isc::dhcp::Dhcpv6Srv::processRenew(), isc::dhcp::Dhcpv4Srv::processRequest(), isc::dhcp::Dhcpv6Srv::processRequest(), isc::dhcp::Dhcpv6Srv::processSolicit(), isc::ha::LeaseUpdateBacklog::push(), isc::dhcp::AllocEngine::reclaimExpiredLeases4Internal(), isc::dhcp::AllocEngine::reclaimExpiredLeases6Internal(), isc::dhcp::TimerMgrImpl::registerTimer(), isc::ha::CommunicationState::rejectedLeaseUpdatesShouldTerminate(), isc::ha::CommunicationState::reportRejectedLeaseUpdate(), isc::ha::CommunicationState::reportSuccessfulLeaseUpdate(), isc::dhcp::Dhcpv4Srv::run(), isc::dhcp::Dhcpv6Srv::run(), isc::dhcp::Dhcpv4Srv::runOne(), isc::dhcp::Dhcpv6Srv::runOne(), isc::dhcp::Dhcpv4Srv::selectSubnet(), isc::dhcp::Dhcpv6Srv::selectSubnet(), isc::dhcp::Dhcpv4Srv::selectSubnet4o6(), isc::dhcp_ddns::NameChangeSender::sendRequest(), isc::ha::QueryFilter::serveDefaultScopes(), isc::ha::QueryFilter::serveFailoverScopes(), isc::ha::QueryFilter::serveNoScopes(), isc::dhcp::Dhcpv4Srv::serverDecline(), isc::ha::QueryFilter::serveScope(), isc::ha::QueryFilter::serveScopeOnly(), isc::ha::QueryFilter::serveScopes(), isc::ha::CommunicationState::setPartnerScopes(), isc::ha::CommunicationState::setPartnerState(), isc::ha::CommunicationState::setPartnerTime(), isc::ha::CommunicationState::setPartnerUnavailable(), isc::ha::CommunicationState::setPartnerUnsentUpdateCount(), isc::dhcp::TimerMgrImpl::setup(), isc::http::HttpConnectionPool::shutdown(), isc::tcp::TcpConnectionPool::shutdown(), isc::ha::LeaseUpdateBacklog::size(), isc::dhcp_ddns::NameChangeSender::skipNext(), isc::config::CmdHttpListener::start(), isc::http::HttpConnectionPool::start(), isc::tcp::MtTcpListenerMgr::start(), isc::tcp::TcpConnectionPool::start(), isc::ha::HAService::startClientAndListener(), isc::ha::CommunicationState::startHeartbeat(), isc::dhcp::Memfile_LeaseMgr::startLeaseStatsQuery4(), isc::dhcp::Memfile_LeaseMgr::startLeaseStatsQuery6(), isc::dhcp::Memfile_LeaseMgr::startPoolLeaseStatsQuery4(), isc::dhcp::Memfile_LeaseMgr::startPoolLeaseStatsQuery6(), isc::dhcp_ddns::NameChangeSender::startSending(), isc::dhcp::Memfile_LeaseMgr::startSubnetLeaseStatsQuery4(), isc::dhcp::Memfile_LeaseMgr::startSubnetLeaseStatsQuery6(), isc::dhcp::Memfile_LeaseMgr::startSubnetRangeLeaseStatsQuery4(), isc::dhcp::Memfile_LeaseMgr::startSubnetRangeLeaseStatsQuery6(), isc::http::HttpConnectionPool::stop(), isc::tcp::TcpConnectionPool::stop(), isc::http::HttpConnectionPool::stopAll(), isc::tcp::TcpConnectionPool::stopAll(), isc::ha::HAService::stopClientAndListener(), isc::ha::CommunicationState::stopHeartbeat(), isc::dhcp::TimerMgrImpl::timersCount(), isc::dhcp::TimerMgrImpl::unregisterTimer(), isc::dhcp::TimerMgrImpl::unregisterTimers(), isc::dhcp::Memfile_LeaseMgr::updateLease4(), isc::dhcp::Memfile_LeaseMgr::updateLease6(), isc::ha::HAService::updatePendingRequest(), isc::ha::CommunicationState::updatePokeTime(), isc::tcp::TcpConnectionPool::usedByRemoteIp(), isc::ha::LeaseUpdateBacklog::wasOverflown(), isc::dhcp::Memfile_LeaseMgr::wipeExtendedInfoTables6(), isc::dhcp::Memfile_LeaseMgr::writeLeases4(), and isc::dhcp::Memfile_LeaseMgr::writeLeases6().
bool isc::util::MultiThreadingMgr::isInCriticalSection | ( | ) |
Is in critical section flag.
Definition at line 89 of file multi_threading_mgr.cc.
Referenced by apply(), enterCriticalSection(), and exitCriticalSection().
|
inline |
Checks if the MultiThreadingMgr
is in the test mode.
MultiThreadingMgr
is in the test mode, false otherwise. Definition at line 169 of file multi_threading_mgr.h.
void isc::util::MultiThreadingMgr::removeAllCriticalSectionCallbacks | ( | ) |
Removes all callbacks in the list of CriticalSection callbacks.
Definition at line 229 of file multi_threading_mgr.cc.
References isc::util::CSCallbackSetList::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 224 of file multi_threading_mgr.cc.
References isc::util::CSCallbackSetList::removeCallbackSet().
Referenced by isc::ha::HAService::stopClientAndListener().
void isc::util::MultiThreadingMgr::setMode | ( | bool | enabled | ) |
Set the multi-threading mode.
enabled | The new mode. |
Definition at line 36 of file multi_threading_mgr.cc.
Referenced by isc::test::MultiThreadingTest::MultiThreadingTest(), isc::test::MultiThreadingTest::~MultiThreadingTest(), and apply().
void isc::util::MultiThreadingMgr::setPacketQueueSize | ( | uint32_t | size | ) |
Set the configured dhcp packet queue size.
size | The dhcp packet queue size. |
Definition at line 114 of file multi_threading_mgr.cc.
References isc::util::ThreadPool< WorkItem, Container >::setMaxQueueSize().
Referenced by apply().
|
inline |
Sets or clears the test mode for MultiThreadingMgr
.
test_mode | A flag which indicates that the MultiThreadingMgr is in the test mode (if true), or not (if false). |
Definition at line 161 of file multi_threading_mgr.h.
Referenced by isc::dhcp::configureDhcp4Server(), and isc::dhcp::configureDhcp6Server().
void isc::util::MultiThreadingMgr::setThreadPoolSize | ( | uint32_t | size | ) |
Set the configured dhcp thread pool size.
size | The dhcp thread pool size. |
Definition at line 104 of file multi_threading_mgr.cc.
Referenced by apply().