7#ifndef MULTI_THREADING_MGR_H
8#define MULTI_THREADING_MGR_H
14#include <boost/noncopyable.hpp>
104 std::list<CSCallbackSet> cb_sets_;
162 test_mode_ = test_mode;
250 void apply(
bool enabled, uint32_t thread_count, uint32_t queue_size);
303 void checkCallbacksPermissions();
311 void callEntryCallbacks();
319 void callExitCallbacks();
336 uint32_t critical_section_count_;
339 uint32_t thread_pool_size_;
342 ThreadPool<std::function<void()>> thread_pool_;
359 std::unique_lock<std::mutex> lock_;
Maintains list of unique CSCallbackSets.
void removeCallbackSet(const std::string &name)
Removes a callback set from the list.
const std::list< CSCallbackSet > & getCallbackSets()
Fetches the list of callback sets.
CSCallbackSetList()
Constructor.
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.
RAII class creating a critical section.
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.
bool isTestMode() const
Checks if the MultiThreadingMgr is in the test mode.
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.
void setTestMode(const bool test_mode)
Sets or clears the test mode for MultiThreadingMgr.
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.
Defines the logger used by the top-level component of kea-lfc.
Embodies a named set of CriticalSection callbacks.
Callback check_cb_
Check permissions callback associated with name.
CSCallbackSet(const std::string &name, const Callback &check_cb, const Callback &entry_cb, const Callback &exit_cb)
Constructor.
std::function< void()> Callback
Defines a callback as a simple void() functor.
Callback entry_cb_
Entry point callback associated with name.
std::string name_
Name by which the callback can be found.
Callback exit_cb_
Exit point callback associated with name.
RAII lock object to protect the code in the same scope with a mutex.
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.