Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Kea
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
450
Issues
450
List
Boards
Labels
Service Desk
Milestones
Merge Requests
75
Merge Requests
75
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ISC Open Source Projects
Kea
Commits
59b9166a
Commit
59b9166a
authored
Oct 22, 2019
by
Francis Dupont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[962-implement-the-multi_threading_mgr-h-idea] Added the Multi Threading Manager
parent
70477262
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
170 additions
and
0 deletions
+170
-0
src/lib/util/Makefile.am
src/lib/util/Makefile.am
+1
-0
src/lib/util/multi_threading_mgr.cc
src/lib/util/multi_threading_mgr.cc
+42
-0
src/lib/util/multi_threading_mgr.h
src/lib/util/multi_threading_mgr.h
+100
-0
src/lib/util/tests/Makefile.am
src/lib/util/tests/Makefile.am
+1
-0
src/lib/util/tests/multi_threading_mgr_unittest.cc
src/lib/util/tests/multi_threading_mgr_unittest.cc
+26
-0
No files found.
src/lib/util/Makefile.am
View file @
59b9166a
...
...
@@ -16,6 +16,7 @@ libkea_util_la_SOURCES += hash.h
libkea_util_la_SOURCES
+=
labeled_value.h labeled_value.cc
libkea_util_la_SOURCES
+=
memory_segment.h
libkea_util_la_SOURCES
+=
memory_segment_local.h memory_segment_local.cc
libkea_util_la_SOURCES
+=
multi_threading_mgr.h multi_threading_mgr.cc
libkea_util_la_SOURCES
+=
optional.h
libkea_util_la_SOURCES
+=
pid_file.h pid_file.cc
libkea_util_la_SOURCES
+=
pointer_util.h
...
...
src/lib/util/multi_threading_mgr.cc
0 → 100644
View file @
59b9166a
// 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 <util/multi_threading_mgr.h>
namespace
isc
{
namespace
util
{
BaseMultiThreadingMgr
::
BaseMultiThreadingMgr
()
:
enabled_
(
false
)
{
}
BaseMultiThreadingMgr
::~
BaseMultiThreadingMgr
()
{
}
bool
BaseMultiThreadingMgr
::
getMode
()
const
{
return
(
enabled_
);
}
void
BaseMultiThreadingMgr
::
setMode
(
bool
enabled
)
{
enabled_
=
enabled
;
}
MultiThreadingMgr
::
MultiThreadingMgr
()
:
BaseMultiThreadingMgr
()
{
}
MultiThreadingMgr
::~
MultiThreadingMgr
()
{
}
BaseMultiThreadingMgr
&
MultiThreadingMgr
::
instance
()
{
static
MultiThreadingMgr
manager
;
return
(
manager
);
}
}
// namespace isc::util
}
// namespace isc
src/lib/util/multi_threading_mgr.h
0 → 100644
View file @
59b9166a
// 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_MGR_H
#define MULTI_THREADING_MGR_H
#include <boost/noncopyable.hpp>
namespace
isc
{
namespace
util
{
/// @file multi_threading_mgr.h Multi Threading Manager.
///
/// This singleton class holds the multi-threading mode.
///
/// It is split into two classes to hide the setMode method from the
/// instance static method.
///
/// The standard way to use it is:
/// @code
/// if (MultiThreadingMgr::instance().getMode) {
/// multi-threaded code
/// } else {
/// single-threaded code
/// }
/// @endcode
///
/// For instance for a class protected by its mutex:
/// @code
/// namespace locked {
/// void foo() { ... }
/// } // end of locked namespace
///
/// void foo() {
/// if (MultiThreadingMgr::instance().getMode) {
/// lock_guard<mutex> lock(mutex_);
/// locked::foo();
/// } else {
/// locked::foo();
/// }
/// }
/// @endcode
/// @brief The base class hiding the setter.
class
BaseMultiThreadingMgr
:
public
boost
::
noncopyable
{
public:
/// @brief Get the mode.
///
/// @return the current mode: true if multi-threading is enabled,
/// false otherwise.
bool
getMode
()
const
;
protected:
/// @brief Constructor.
BaseMultiThreadingMgr
();
/// @brief Destructor.
virtual
~
BaseMultiThreadingMgr
();
/// @brief Set the mode.
///
/// @param mode The new mode.
void
setMode
(
bool
enabled
);
private:
/// @brief the current mode.
bool
enabled_
;
};
/// @brief The class providing instance and setter.
class
MultiThreadingMgr
:
public
BaseMultiThreadingMgr
{
public:
/// @brief Returns a single instance of Multi Threading Manager.
///
/// MultiThreadingMgr is a singleton and this method is the only way
/// of accessing it.
///
/// @return the single instance.
static
BaseMultiThreadingMgr
&
instance
();
using
BaseMultiThreadingMgr
::
setMode
;
protected:
/// @brief Constructor.
MultiThreadingMgr
();
/// @brief Destructor.
virtual
~
MultiThreadingMgr
();
};
}
// namespace isc::dhcp
}
// namespace isc
#endif // MULTI_THREADING_MGR_H
src/lib/util/tests/Makefile.am
View file @
59b9166a
...
...
@@ -44,6 +44,7 @@ run_unittests_SOURCES += labeled_value_unittest.cc
run_unittests_SOURCES
+=
memory_segment_local_unittest.cc
run_unittests_SOURCES
+=
memory_segment_common_unittest.h
run_unittests_SOURCES
+=
memory_segment_common_unittest.cc
run_unittests_SOURCES
+=
multi_threading_mgr_unittest.cc
run_unittests_SOURCES
+=
optional_unittest.cc
run_unittests_SOURCES
+=
pid_file_unittest.cc
run_unittests_SOURCES
+=
process_spawn_unittest.cc
...
...
src/lib/util/tests/multi_threading_mgr_unittest.cc
0 → 100644
View file @
59b9166a
// 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 <util/multi_threading_mgr.h>
#include <gtest/gtest.h>
using
namespace
isc
::
util
;
// Verifies that the default mode is false (MT disabled).
TEST
(
MultiThreadingMgrTest
,
default
)
{
EXPECT_FALSE
(
MultiThreadingMgr
::
instance
().
getMode
());
}
// Verifies that the instance can be dynamic cast and setter works.
TEST
(
MultiThreadingMgrTest
,
setMode
)
{
EXPECT_NO_THROW
(
dynamic_cast
<
MultiThreadingMgr
&>
(
MultiThreadingMgr
::
instance
()).
setMode
(
true
));
EXPECT_TRUE
(
MultiThreadingMgr
::
instance
().
getMode
());
EXPECT_NO_THROW
(
dynamic_cast
<
MultiThreadingMgr
&>
(
MultiThreadingMgr
::
instance
()).
setMode
(
false
));
EXPECT_FALSE
(
MultiThreadingMgr
::
instance
().
getMode
());
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment