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>&
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a function is called in a prohibited way.
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.
const std::list< CSCallbackSet > & getCallbackSets()
Fetches the list of callback sets.
void removeAll()
Removes all callbacks from the list.
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.
MultiThreadingCriticalSection()
Constructor.
virtual ~MultiThreadingCriticalSection()
Destructor.
void removeAllCriticalSectionCallbacks()
Removes all callbacks in the list of CriticalSection callbacks.
void setMode(bool enabled)
Set the multi-threading mode.
virtual ~MultiThreadingMgr()
Destructor.
MultiThreadingMgr()
Constructor.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
void enterCriticalSection()
Enter critical section.
void setThreadPoolSize(uint32_t size)
Set the configured dhcp thread pool size.
uint32_t getPacketQueueSize()
Get the configured dhcp packet queue size.
void removeCriticalSectionCallbacks(const std::string &name)
Removes the set of callbacks associated with a given name from the list of CriticalSection callbacks.
void setPacketQueueSize(uint32_t size)
Set the configured dhcp packet queue size.
uint32_t getThreadPoolSize() const
Get the configured dhcp thread pool size.
ThreadPool< std::function< void()> > & getThreadPool()
Get the dhcp thread pool.
bool isInCriticalSection()
Is in critical section flag.
static uint32_t detectThreadCount()
The system current detected hardware concurrency thread count.
void apply(bool enabled, uint32_t thread_count, uint32_t queue_size)
Apply the multi-threading related settings.
bool getMode() const
Get the multi-threading mode.
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 exitCriticalSection()
Exit critical section.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-lfc.
Embodies a named set of CriticalSection callbacks.
std::function< void()> Callback
Defines a callback as a simple void() functor.
MultiThreadingLock(std::mutex &mutex)
Constructor locks the mutex if multi-threading is enabled.
Defines a thread pool which uses a thread pool queue for managing work items.
void setMaxQueueSize(size_t max_queue_size)
set maximum number of work items in the queue
void reset()
reset the thread pool stopping threads and clearing the internal queue
void start(uint32_t thread_count)
start all the threads
size_t getMaxQueueSize()
get maximum number of work items in the queue
size_t size()
size number of thread pool threads
void stop()
stop all the threads