Kea 2.7.6
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 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 MultiThreadingMgrinstance ()
 Returns a single instance of Multi Threading Manager.
 

Protected Member Functions

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

Detailed Description

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:

multi-threaded code
} else {
single-threaded code
}
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
bool getMode() const
Get the multi-threading mode.

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 136 of file multi_threading_mgr.h.

Constructor & Destructor Documentation

◆ MultiThreadingMgr()

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

Constructor.

Definition at line 16 of file multi_threading_mgr.cc.

◆ ~MultiThreadingMgr()

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

Destructor.

Definition at line 21 of file multi_threading_mgr.cc.

Member Function Documentation

◆ addCriticalSectionCallbacks()

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.

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.
check_cbCallback to check current thread permissions to call the CriticalSection entry and exit callbacks.
entry_cbCallback to invoke upon CriticalSection entry. Cannot be empty.
exit_cbCallback 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().

+ Here is the call graph for this function:

◆ apply()

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.

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 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().

+ Here is the call graph for this function:

◆ detectThreadCount()

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 119 of file multi_threading_mgr.cc.

Referenced by apply(), and isc::ha::HAConfig::validate().

◆ enterCriticalSection()

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.

Note
This function swallows exceptions thrown by all entry callbacks without logging to avoid breaking the CS chain.

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().

+ Here is the call graph for this function:

◆ exitCriticalSection()

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.

Note
This function swallows exceptions thrown by all exit callbacks without logging to avoid breaking the CS chain.

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().

+ Here is the call graph for this function:

◆ getMode()

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 31 of file multi_threading_mgr.cc.

Referenced by isc::dhcp::ClientHandler::~ClientHandler(), enterCriticalSection(), and exitCriticalSection().

◆ getPacketQueueSize()

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

Get the configured dhcp packet queue size.

Returns
The dhcp packet queue size.

Definition at line 109 of file multi_threading_mgr.cc.

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

+ Here is the call graph for this function:

◆ getThreadPool()

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

◆ getThreadPoolSize()

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

Get the configured dhcp thread pool size.

Returns
The dhcp thread pool size.

Definition at line 99 of file multi_threading_mgr.cc.

Referenced by enterCriticalSection(), and exitCriticalSection().

◆ instance()

MultiThreadingMgr & isc::util::MultiThreadingMgr::instance ( )
static

Returns a single instance of Multi Threading Manager.

MultiThreadingMgr is a singleton and this method is the only way of accessing it.

Returns
the single instance.

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().

◆ isInCriticalSection()

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

Is in critical section flag.

Returns
The critical section flag.

Definition at line 89 of file multi_threading_mgr.cc.

Referenced by apply(), enterCriticalSection(), and exitCriticalSection().

◆ isTestMode()

bool isc::util::MultiThreadingMgr::isTestMode ( ) const
inline

Checks if the MultiThreadingMgr is in the test mode.

Returns
true if the MultiThreadingMgr is in the test mode, false otherwise.

Definition at line 169 of file multi_threading_mgr.h.

◆ removeAllCriticalSectionCallbacks()

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().

+ Here is the call graph for this function:

◆ removeCriticalSectionCallbacks()

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 224 of file multi_threading_mgr.cc.

References isc::util::CSCallbackSetList::removeCallbackSet().

Referenced by isc::ha::HAService::stopClientAndListener().

+ Here is the call graph for this function:

◆ setMode()

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

Set the multi-threading mode.

Parameters
enabledThe new mode.

Definition at line 36 of file multi_threading_mgr.cc.

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

◆ setPacketQueueSize()

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

Set the configured dhcp packet queue size.

Parameters
sizeThe dhcp packet queue size.

Definition at line 114 of file multi_threading_mgr.cc.

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

Referenced by apply().

+ Here is the call graph for this function:

◆ setTestMode()

void isc::util::MultiThreadingMgr::setTestMode ( const bool test_mode)
inline

Sets or clears the test mode for MultiThreadingMgr.

Parameters
test_modeA 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().

◆ setThreadPoolSize()

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

Set the configured dhcp thread pool size.

Parameters
sizeThe dhcp thread pool size.

Definition at line 104 of file multi_threading_mgr.cc.

Referenced by apply().


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