From fc5ddfaab05254f26735144910dbd31eb9dba368 Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Fri, 21 Feb 2020 18:51:06 +0200 Subject: [PATCH] [#1016] implemented startPktProcessing and stopPktProcessing --- src/lib/dhcpsrv/multi_threading_utils.cc | 16 ++++++++++------ src/lib/dhcpsrv/multi_threading_utils.h | 8 ++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/lib/dhcpsrv/multi_threading_utils.cc b/src/lib/dhcpsrv/multi_threading_utils.cc index 767d4fbdb4..293c53f1b3 100644 --- a/src/lib/dhcpsrv/multi_threading_utils.cc +++ b/src/lib/dhcpsrv/multi_threading_utils.cc @@ -18,16 +18,20 @@ namespace dhcp { void MultiThreadingCriticalSection::stopPktProcessing() { - isc_throw(NotImplemented, - "MultiThreadingCriticalSection::stopPktProcessing " - "is not yet implemented"); + auto& thread_pool = MultiThreadingMgr::instance().getPktThreadPool(); + auto size = MultiThreadingMgr::instance().getPktThreadPoolSize(); + if (size) { + thread_pool.stop(); + } } void MultiThreadingCriticalSection::startPktProcessing() { - isc_throw(NotImplemented, - "MultiThreadingCriticalSection::startPktProcessing " - "is not yet implemented"); + auto& thread_pool = MultiThreadingMgr::instance().getPktThreadPool(); + auto size = MultiThreadingMgr::instance().getPktThreadPoolSize(); + if (size) { + thread_pool.start(size); + } } MultiThreadingCriticalSection::MultiThreadingCriticalSection() { diff --git a/src/lib/dhcpsrv/multi_threading_utils.h b/src/lib/dhcpsrv/multi_threading_utils.h index c139f938a5..a37f376bf3 100644 --- a/src/lib/dhcpsrv/multi_threading_utils.h +++ b/src/lib/dhcpsrv/multi_threading_utils.h @@ -27,21 +27,29 @@ void startPktProcessing(); /// /// @note: the multi-threading mode MUST NOT be changed in the RAII /// @c MultiThreadingCriticalSection body. +/// @note: starting and stopping the packet thread pool should be handled +/// in the main thread, if done on one of the processing threads will cause a +/// dead-lock class MultiThreadingCriticalSection : public boost::noncopyable { public: + /// @brief Constructor. + /// /// Entering the critical section. MultiThreadingCriticalSection(); /// @brief Destructor. + /// /// Leaving the critical section. virtual ~MultiThreadingCriticalSection(); /// @brief Class method stopping and joining all threads of the pool. + /// /// @throw isc::NotImplemented until is implemented. static void stopPktProcessing(); /// @brief Class method (re)starting threads of the pool. + /// /// @throw isc::NotImplemented until is implemented. static void startPktProcessing(); };