Commit 41cca23f authored by Francis Dupont's avatar Francis Dupont

[962-implement-the-multi_threading_mgr-h-idea] Merged into one class

parent bc4c5d7d
......@@ -9,34 +9,28 @@
namespace isc {
namespace util {
BaseMultiThreadingMgr::BaseMultiThreadingMgr() : enabled_(false) {
MultiThreadingMgr::MultiThreadingMgr() : enabled_(false) {
}
BaseMultiThreadingMgr::~BaseMultiThreadingMgr() {
MultiThreadingMgr::~MultiThreadingMgr() {
}
MultiThreadingMgr&
MultiThreadingMgr::instance() {
static MultiThreadingMgr manager;
return (manager);
}
bool
BaseMultiThreadingMgr::getMode() const
MultiThreadingMgr::getMode() const
{
return (enabled_);
}
void
BaseMultiThreadingMgr::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
......@@ -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
......@@ -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());
}
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