15 : enabled_(false), critical_section_count_(0), thread_pool_size_(0) {
40 ++critical_section_count_;
45 if (critical_section_count_ == 0) {
48 --critical_section_count_;
54 return (critical_section_count_ != 0);
64 return (thread_pool_size_);
69 thread_pool_size_ = size;
84 return (std::thread::hardware_concurrency());
103 if (thread_pool_.
size()) {
110 thread_pool_.
start(thread_count);
114 thread_pool_.
reset();
122 MultiThreadingMgr::stopProcessing() {
141 MultiThreadingMgr::startProcessing() {
194 <<
" cannot be empty");
199 <<
" cannot be empty");
202 for (
auto const& callback : cb_pairs_) {
203 if (callback.name_ == name) {
205 <<
" already exist");
214 for (
auto it = cb_pairs_.begin(); it != cb_pairs_.end(); ++it) {
215 if ((*it).name_ == name) {
227 const std::list<CSCallbackPair>&
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
MultiThreadingMgr()
Constructor.
MultiThreadingCriticalSection()
Constructor.
uint32_t getThreadPoolSize() const
Get the configured dhcp thread pool size.
void removeAllCriticalSectionCallbacks()
Removes all callbacks in the list of CriticalSection callbacks.
void enterCriticalSection()
Enter critical section.
void exitCriticalSection()
Exit critical section.
void setThreadPoolSize(uint32_t size)
Set the configured dhcp thread pool size.
void start(uint32_t thread_count)
start all the threads
void setMaxQueueSize(size_t max_queue_size)
set maximum number of work items in the queue
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
std::function< void()> Callback
Defines a callback as a simple void() functor.
size_t size()
size number of thread pool threads
void setMode(bool enabled)
Set the multi-threading mode.
bool getMode() const
Get the multi-threading mode.
void removeAll()
Removes all callbacks from the list.
const std::list< CSCallbackPair > & getCallbackPairs()
Fetches the list of callback pairs.
void addCallbackPair(const std::string &name, const CSCallbackPair::Callback &entry_cb, const CSCallbackPair::Callback &exit_cb)
Adds a callback pair to the list.
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.
virtual ~MultiThreadingMgr()
Destructor.
void setPacketQueueSize(uint32_t size)
Set the configured dhcp packet queue size.
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual ~MultiThreadingCriticalSection()
Destructor.
ThreadPool< std::function< void()> > & getThreadPool()
Get the dhcp thread pool.
void removeCriticalSectionCallbacks(const std::string &name)
Removes the set of callbacks associated with a given name from the list of CriticalSection callbacks...
size_t getMaxQueueSize()
get maximum number of work items in the queue
A generic exception that is thrown if a function is called in a prohibited way.
void stop()
stop all the threads
void removeCallbackPair(const std::string &name)
Removes a callback pair from the list.
void reset()
reset the thread pool stopping threads and clearing the internal queue
bool isInCriticalSection()
Is in critical section flag.
Defines a thread pool which uses a thread pool queue for managing work items.
static uint32_t detectThreadCount()
The system current detected hardware concurrency thread count.
uint32_t getPacketQueueSize()
Get the configured dhcp packet queue size.
void apply(bool enabled, uint32_t thread_count, uint32_t queue_size)
Apply the multi-threading related settings.
Embodies a named pair of CriticalSection callbacks.