15 : enabled_(false), critical_section_count_(0), thread_pool_size_(0) {
39 checkCallbacksPermissions();
45 ++critical_section_count_;
67 --critical_section_count_;
79 return (critical_section_count_ != 0);
89 return (thread_pool_size_);
94 thread_pool_size_ = size;
109 return (std::thread::hardware_concurrency());
128 if (thread_pool_.
size()) {
135 thread_pool_.
start(thread_count);
139 thread_pool_.
reset();
147 MultiThreadingMgr::checkCallbacksPermissions() {
170 MultiThreadingMgr::callEntryCallbacks() {
173 for (
auto cb_it = callbacks.begin(); cb_it != callbacks.end(); cb_it++) {
175 (cb_it->entry_cb_)();
186 MultiThreadingMgr::callExitCallbacks() {
189 for (
auto cb_it = callbacks.rbegin(); cb_it != callbacks.rend(); cb_it++) {
232 lock_ = std::unique_lock<std::mutex>(mutex);
247 <<
" cannot be empty");
252 <<
" cannot be empty");
257 <<
" cannot be empty");
260 for (
auto const& callback : cb_sets_) {
261 if (callback.name_ == name) {
263 <<
" already exist");
267 cb_sets_.push_back(
CSCallbackSet(name, check_cb, entry_cb, exit_cb));
272 for (
auto it = cb_sets_.begin(); it != cb_sets_.end(); ++it) {
273 if ((*it).name_ == name) {
285 const std::list<CSCallbackSet>&
Exception thrown when a worker thread is trying to stop or pause the respective thread pool (which wo...
void removeCallbackSet(const std::string &name)
Removes a callback set from the list.
Embodies a named set of CriticalSection callbacks.
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.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
uint32_t getThreadPoolSize() const
Get the configured dhcp thread pool size.
MultiThreadingMgr()
Constructor.
MultiThreadingCriticalSection()
Constructor.
void removeAllCriticalSectionCallbacks()
Removes all callbacks in the list of CriticalSection callbacks.
void enterCriticalSection()
Enter critical section.
void addCallbackSet(const std::string &name, const CSCallbackSet::Callback &check_cb, const CSCallbackSet::Callback &entry_cb, const CSCallbackSet::Callback &exit_cb)
Adds a callback set to the list.
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...
size_t size()
size number of thread pool threads
void setMode(bool enabled)
Set the multi-threading mode.
MultiThreadingLock(std::mutex &mutex)
Constructor locks the mutex if multi-threading is enabled.
bool getMode() const
Get the multi-threading mode.
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-lfc.
std::function< void()> Callback
Defines a callback as a simple void() functor.
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 removeAll()
Removes all callbacks 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.
const std::list< CSCallbackSet > & getCallbackSets()
Fetches the list of callback sets.
void apply(bool enabled, uint32_t thread_count, uint32_t queue_size)
Apply the multi-threading related settings.