From 66083a3f993c05963e4660bc2182c9ece76104aa Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Mon, 4 Nov 2019 20:07:07 +0200 Subject: [PATCH] [#886, !508] renamed class and moved sources --- src/lib/dhcpsrv/Makefile.am | 1 - src/lib/dhcpsrv/tests/Makefile.am | 1 - src/lib/util/Makefile.am | 1 + src/lib/util/tests/Makefile.am | 1 + .../tests/thread_resource_unittest.cc} | 42 +++++++++---------- .../thread_resource.h} | 2 +- 6 files changed, 24 insertions(+), 24 deletions(-) rename src/lib/{dhcpsrv/tests/thread_resource_mgr_unittest.cc => util/tests/thread_resource_unittest.cc} (90%) rename src/lib/{dhcpsrv/thread_resource_mgr.h => util/thread_resource.h} (98%) diff --git a/src/lib/dhcpsrv/Makefile.am b/src/lib/dhcpsrv/Makefile.am index 1974c9a9b2..d0076959dd 100644 --- a/src/lib/dhcpsrv/Makefile.am +++ b/src/lib/dhcpsrv/Makefile.am @@ -118,7 +118,6 @@ 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 -libkea_dhcpsrv_la_SOURCES += thread_resource_mgr.h if HAVE_MYSQL libkea_dhcpsrv_la_SOURCES += mysql_lease_mgr.cc mysql_lease_mgr.h diff --git a/src/lib/dhcpsrv/tests/Makefile.am b/src/lib/dhcpsrv/tests/Makefile.am index 8684f6379e..d9cac94776 100644 --- a/src/lib/dhcpsrv/tests/Makefile.am +++ b/src/lib/dhcpsrv/tests/Makefile.am @@ -124,7 +124,6 @@ libdhcpsrv_unittests_SOURCES += shared_networks_list_parser_unittest.cc libdhcpsrv_unittests_SOURCES += srv_config_unittest.cc libdhcpsrv_unittests_SOURCES += subnet_unittest.cc libdhcpsrv_unittests_SOURCES += test_get_callout_handle.cc test_get_callout_handle.h -libdhcpsrv_unittests_SOURCES += thread_resource_mgr_unittest.cc libdhcpsrv_unittests_SOURCES += triplet_unittest.cc libdhcpsrv_unittests_SOURCES += test_utils.cc test_utils.h libdhcpsrv_unittests_SOURCES += timer_mgr_unittest.cc diff --git a/src/lib/util/Makefile.am b/src/lib/util/Makefile.am index cb643556d9..0f0e529a17 100644 --- a/src/lib/util/Makefile.am +++ b/src/lib/util/Makefile.am @@ -28,6 +28,7 @@ libkea_util_la_SOURCES += state_model.cc state_model.h libkea_util_la_SOURCES += stopwatch.cc stopwatch.h libkea_util_la_SOURCES += stopwatch_impl.cc stopwatch_impl.h libkea_util_la_SOURCES += strutil.h strutil.cc +libkea_util_la_SOURCES += thread_resource.h libkea_util_la_SOURCES += time_utilities.h time_utilities.cc libkea_util_la_SOURCES += versioned_csv_file.h versioned_csv_file.cc libkea_util_la_SOURCES += watch_socket.cc watch_socket.h diff --git a/src/lib/util/tests/Makefile.am b/src/lib/util/tests/Makefile.am index 68b3e31ea3..ce86032a40 100644 --- a/src/lib/util/tests/Makefile.am +++ b/src/lib/util/tests/Makefile.am @@ -53,6 +53,7 @@ run_unittests_SOURCES += random_number_generator_unittest.cc run_unittests_SOURCES += staged_value_unittest.cc run_unittests_SOURCES += state_model_unittest.cc run_unittests_SOURCES += strutil_unittest.cc +run_unittests_SOURCES += thread_resource_unittest.cc run_unittests_SOURCES += time_utilities_unittest.cc run_unittests_SOURCES += range_utilities_unittest.cc run_unittests_SOURCES += signal_set_unittest.cc diff --git a/src/lib/dhcpsrv/tests/thread_resource_mgr_unittest.cc b/src/lib/util/tests/thread_resource_unittest.cc similarity index 90% rename from src/lib/dhcpsrv/tests/thread_resource_mgr_unittest.cc rename to src/lib/util/tests/thread_resource_unittest.cc index eef73cf2c0..09a35d8052 100644 --- a/src/lib/dhcpsrv/tests/thread_resource_mgr_unittest.cc +++ b/src/lib/util/tests/thread_resource_unittest.cc @@ -8,7 +8,7 @@ #include -#include +#include #include @@ -121,15 +121,15 @@ std::mutex Resource::mutex_; template std::set Resource::set_; -/// @brief Test Fixture for testing isc::dhcp::ThreadResourceMgr -class ThreadResourceMgrTest : public ::testing::Test { +/// @brief Test Fixture for testing isc::dhcp::ThreadResource +class ThreadResourceTest : public ::testing::Test { public: /// @brief Constructor - ThreadResourceMgrTest() : wait_thread_(false), wait_(false) { + ThreadResourceTest() : wait_thread_(false), wait_(false) { } /// @brief Destructor - ~ThreadResourceMgrTest() { + ~ThreadResourceTest() { } /// @brief flag which indicates if main thread should wait for the test @@ -166,13 +166,13 @@ public: wait_cv_.notify_all(); } - /// @brief reset resource manager for the specific class type and perform - /// sanity checks, then reset the wait flag so threads wait for the main - /// thread signal to exit + /// @brief reset resource for the specific class type and perform sanity + /// checks, then reset the wait flag so threads wait for the main thread + /// signal to exit template void reset() { - // reset the resource manager - get() = make_shared>>(); + // reset the resource + get() = make_shared>>(); // perform sanity checks sanityCheck(); // reset the wait flag @@ -201,13 +201,13 @@ public: ASSERT_EQ(Resource::destroyedCount(), expected_destroyed); } - /// @brief get the instance of the resource manager responsible for a - /// specific class type + /// @brief get the instance of the resource responsible for a specific class + /// type /// - /// @return the resource manager responsible for a specific class type + /// @return the resource responsible for a specific class type template - shared_ptr>> &get() { - static shared_ptr>> container; + shared_ptr>> &get() { + static shared_ptr>> container; return container; } @@ -293,8 +293,8 @@ private: /// It is very important for the threads to run in parallel and not just run and /// join the thread as this will cause newer threads to use the old thread id /// and receive the same resource. -/// If destroying threads, the resource manager should also be reset. -TEST_F(ThreadResourceMgrTest, testThreadResources) { +/// If destroying threads, the resource should also be reset. +TEST_F(ThreadResourceTest, testThreadResources) { std::list> threads; // reset statistics for uint_32 type @@ -305,14 +305,14 @@ TEST_F(ThreadResourceMgrTest, testThreadResources) { resetWaitThread(); // call run on a different thread and verify statistics threads.push_back(std::make_shared(std::bind( - &ThreadResourceMgrTest::run, this, 2, 2, 0, true))); + &ThreadResourceTest::run, this, 2, 2, 0, true))); // wait for the thread to process wait(); // configure wait for test thread resetWaitThread(); // call run again on a different thread and verify statistics threads.push_back(std::make_shared(std::bind( - &ThreadResourceMgrTest::run, this, 3, 3, 0, true))); + &ThreadResourceTest::run, this, 3, 3, 0, true))); // wait for the thread to process wait(); // signal all threads @@ -336,14 +336,14 @@ TEST_F(ThreadResourceMgrTest, testThreadResources) { resetWaitThread(); // call run on a different thread and verify statistics threads.push_back(std::make_shared(std::bind( - &ThreadResourceMgrTest::run, this, 2, 2, 0, true))); + &ThreadResourceTest::run, this, 2, 2, 0, true))); // wait for the thread to process wait(); // configure wait for test thread resetWaitThread(); // call run again on a different thread and verify statistics threads.push_back(std::make_shared(std::bind( - &ThreadResourceMgrTest::run, this, 3, 3, 0, true))); + &ThreadResourceTest::run, this, 3, 3, 0, true))); // wait for the thread to process wait(); // signal all threads diff --git a/src/lib/dhcpsrv/thread_resource_mgr.h b/src/lib/util/thread_resource.h similarity index 98% rename from src/lib/dhcpsrv/thread_resource_mgr.h rename to src/lib/util/thread_resource.h index 405e92f611..bd360cbc7c 100644 --- a/src/lib/dhcpsrv/thread_resource_mgr.h +++ b/src/lib/util/thread_resource.h @@ -16,7 +16,7 @@ namespace isc { namespace dhcp { template -class ThreadResourceMgr { +class ThreadResource { typedef std::shared_ptr ResourcePtr; public: /// @brief function to retrieve the specific resource of calling thread -- 2.47.2