Commit 37e3e010 authored by Francis Dupont's avatar Francis Dupont

[970-implement-multi-threading-critical-section] First version

parent 46052102
......@@ -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
......
// 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 <config.h>
#include <dhcpsrv/multi_threading_utils.h>
#include <util/multi_threading_mgr.h>
#include <exceptions/exceptions.h>
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();
}
}
}
}
// 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 <boost/noncopyable.hpp>
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment