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
445
Issues
445
List
Boards
Labels
Service Desk
Milestones
Merge Requests
71
Merge Requests
71
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
41cca23f
Commit
41cca23f
authored
Oct 23, 2019
by
Francis Dupont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[962-implement-the-multi_threading_mgr-h-idea] Merged into one class
parent
bc4c5d7d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
53 deletions
+28
-53
src/lib/util/multi_threading_mgr.cc
src/lib/util/multi_threading_mgr.cc
+10
-16
src/lib/util/multi_threading_mgr.h
src/lib/util/multi_threading_mgr.h
+16
-35
src/lib/util/tests/multi_threading_mgr_unittest.cc
src/lib/util/tests/multi_threading_mgr_unittest.cc
+2
-2
No files found.
src/lib/util/multi_threading_mgr.cc
View file @
41cca23f
...
...
@@ -9,34 +9,28 @@
namespace
isc
{
namespace
util
{
BaseMultiThreadingMgr
::
Base
MultiThreadingMgr
()
:
enabled_
(
false
)
{
MultiThreadingMgr
::
MultiThreadingMgr
()
:
enabled_
(
false
)
{
}
BaseMultiThreadingMgr
::~
BaseMultiThreadingMgr
()
{
MultiThreadingMgr
::~
MultiThreadingMgr
()
{
}
MultiThreadingMgr
&
MultiThreadingMgr
::
instance
()
{
static
MultiThreadingMgr
manager
;
return
(
manager
);
}
bool
Base
MultiThreadingMgr
::
getMode
()
const
MultiThreadingMgr
::
getMode
()
const
{
return
(
enabled_
);
}
void
Base
MultiThreadingMgr
::
setMode
(
bool
enabled
)
{
MultiThreadingMgr
::
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
View file @
41cca23f
...
...
@@ -12,13 +12,10 @@
namespace
isc
{
namespace
util
{
/// @
file multi_threading_mgr.h
Multi Threading Manager.
/// @
brief
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()) {
...
...
@@ -43,58 +40,42 @@ namespace util {
/// }
/// }
/// @endcode
/// @brief The base class hiding the setter.
class
BaseMultiThreadingMgr
:
public
boost
::
noncopyable
{
class
MultiThreadingMgr
:
public
boost
::
noncopyable
{
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
MultiThreadingMgr
&
instance
();
/// @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
();
private:
/// @brief the current mode.
bool
enabled_
;
};
}
// namespace isc::
dhcp
}
// namespace isc::
util
}
// namespace isc
#endif // MULTI_THREADING_MGR_H
src/lib/util/tests/multi_threading_mgr_unittest.cc
View file @
41cca23f
...
...
@@ -19,8 +19,8 @@ TEST(MultiThreadingMgrTest, default) {
// 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_NO_THROW
(
MultiThreadingMgr
::
instance
(
).
setMode
(
true
));
EXPECT_TRUE
(
MultiThreadingMgr
::
instance
().
getMode
());
EXPECT_NO_THROW
(
dynamic_cast
<
MultiThreadingMgr
&>
(
MultiThreadingMgr
::
instance
()
).
setMode
(
false
));
EXPECT_NO_THROW
(
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