From: Francis Dupont Date: Mon, 4 Nov 2019 14:48:31 +0000 (+0100) Subject: [970-implement-multi-threading-critical-section] First version X-Git-Tag: Kea-1.7.2~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37e3e0102416c5cbc1ba58087e8506fc92b4776c;p=thirdparty%2Fkea.git [970-implement-multi-threading-critical-section] First version --- diff --git a/src/lib/dhcpsrv/Makefile.am b/src/lib/dhcpsrv/Makefile.am index 948f01566a..d0076959dd 100644 --- a/src/lib/dhcpsrv/Makefile.am +++ b/src/lib/dhcpsrv/Makefile.am @@ -117,6 +117,7 @@ libkea_dhcpsrv_la_SOURCES += lease_mgr.cc lease_mgr.h libkea_dhcpsrv_la_SOURCES += lease_mgr_factory.cc lease_mgr_factory.h libkea_dhcpsrv_la_SOURCES += memfile_lease_mgr.cc memfile_lease_mgr.h libkea_dhcpsrv_la_SOURCES += memfile_lease_storage.h +libkea_dhcpsrv_la_SOURCES += multi_threading_utils.h multi_threading_utils.cc if HAVE_MYSQL libkea_dhcpsrv_la_SOURCES += mysql_lease_mgr.cc mysql_lease_mgr.h diff --git a/src/lib/dhcpsrv/multi_threading_utils.cc b/src/lib/dhcpsrv/multi_threading_utils.cc new file mode 100644 index 0000000000..edc7c43a9f --- /dev/null +++ b/src/lib/dhcpsrv/multi_threading_utils.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include +#include +#include + +using namespace isc::util; + +namespace isc { +namespace dhcp { + +void +MultiThreadingCriticalSection::stop_pkt_processing() { + isc_throw(NotImplemented, + "MultiThreadingCriticalSection::stop_pkt_processing " + "is not yet implemented"); +} + +void +MultiThreadingCriticalSection::start_pkt_processing() { + isc_throw(NotImplemented, + "MultiThreadingCriticalSection::start_pkt_processing " + "is not yet implemented"); +} + +MultiThreadingCriticalSection::MultiThreadingCriticalSection() + : enabled_(MultiThreadingMgr::instance().getMode()) { + if (enabled_) { + stop_pkt_processing(); + } +} + +MultiThreadingCriticalSection::~MultiThreadingCriticalSection() { + if (enabled_) { + start_pkt_processing(); + } +} + +} +} diff --git a/src/lib/dhcpsrv/multi_threading_utils.h b/src/lib/dhcpsrv/multi_threading_utils.h new file mode 100644 index 0000000000..3245244d48 --- /dev/null +++ b/src/lib/dhcpsrv/multi_threading_utils.h @@ -0,0 +1,52 @@ +// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef MULTI_THREADING_UTIL_H +#define MULTI_THREADING_UTIL_H + +#include + +namespace isc { +namespace dhcp { + +/// @note: everything here MUST be used only from the main thread. +/// When called from a thread of the pool it can deadlock. + +/// @brief Function stopping and joining all threads of the pool. +/// #throw isc::NotImplemented until is implemented. +void stop_pkt_processing(); + +/// @brief Function (re)starting threads of the pool. +/// #throw isc::NotImplemented until is implemented. +void start_pkt_processing(); + +/// @brief RAII class creating a critical section. +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 stop_pkt_processing(); + + /// @brief Class method (re)starting threads of the pool. + /// @throw isc::NotImplemented until is implemented. + static void start_pkt_processing(); + +private: + /// @brief Local copy of the multi-threading mode. + bool enabled_; +}; + +} +} +#endif // MULTI_THREADING_UTIL_H