diff --git a/src/include/dbconnector/pool/connection_pool.hpp b/src/include/dbconnector/pool/connection_pool.hpp index e4c5c67..ea0cf71 100644 --- a/src/include/dbconnector/pool/connection_pool.hpp +++ b/src/include/dbconnector/pool/connection_pool.hpp @@ -47,6 +47,7 @@ class ConnectionPool : public std::enable_shared_from_this reaper_shutdown_flag {false}; + std::atomic reaper_shutdown_flag {true}; std::atomic tl_cache_enabled {false}; std::atomic tl_cache_hits {0}; diff --git a/src/include/dbconnector/pool/connection_pool_impl.hpp b/src/include/dbconnector/pool/connection_pool_impl.hpp index c52d83e..3e95bd8 100644 --- a/src/include/dbconnector/pool/connection_pool_impl.hpp +++ b/src/include/dbconnector/pool/connection_pool_impl.hpp @@ -590,6 +590,11 @@ void ConnectionPool::ReaperLoop() { } } +template +bool ConnectionPool::IsReaperRunning() { + return !reaper_shutdown_flag.load(std::memory_order_relaxed); +} + template bool ConnectionPool::EnsureReaperRunning() { if (!TimeoutEnabled()) { diff --git a/test/test_pool.cpp b/test/test_pool.cpp index 5da8823..8b646f7 100644 --- a/test/test_pool.cpp +++ b/test/test_pool.cpp @@ -232,10 +232,12 @@ TEST_CASE("Test pool disable running", group_name) { TEST_CASE("Test pool with a reaper", group_name) { auto pool = std::make_shared(4, 1000, false); + REQUIRE(!pool->IsReaperRunning()); REQUIRE(!pool->EnsureReaperRunning()); pool->SetMaxLifetimeMillis(1000); REQUIRE(pool->EnsureReaperRunning()); REQUIRE(pool->EnsureReaperRunning()); + REQUIRE(pool->IsReaperRunning()); { auto conn = pool->WaitAcquire(); @@ -269,10 +271,13 @@ TEST_CASE("Test pool with a reaper", group_name) { TEST_CASE("Test pool with a reaper restart", group_name) { auto pool = std::make_shared(4, 1000, false); + REQUIRE(!pool->IsReaperRunning()); REQUIRE(!pool->EnsureReaperRunning()); pool->SetMaxLifetimeMillis(1000); REQUIRE(pool->EnsureReaperRunning()); + REQUIRE(pool->IsReaperRunning()); pool->ShutdownReaper(); + REQUIRE(!pool->IsReaperRunning()); { auto conn = pool->WaitAcquire();