From 5c72ecb74b98b041ae32f08c252f5b61fd5391ce Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 7 Sep 2021 20:18:41 +0900 Subject: [PATCH 1/3] Add ThreadPool::getThreadCount() Without the previously removed THREADCOUNT constant, there was no way to query the ThreadCount from outside the class. This function provides this. --- src/EC/ThreadPool.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/EC/ThreadPool.hpp b/src/EC/ThreadPool.hpp index 22da28e..d3808ec 100644 --- a/src/EC/ThreadPool.hpp +++ b/src/EC/ThreadPool.hpp @@ -172,6 +172,13 @@ public: return fnQueue.empty(); } + /*! + \brief Returns the ThreadCount that this class was created with. + */ + unsigned int getThreadCount() { + return SIZE; + } + private: std::vector threads; std::atomic_bool isAlive; From 4fd463a87047146daac82e80f9305494107f15ca Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 7 Sep 2021 20:21:20 +0900 Subject: [PATCH 2/3] Add tests for ThreadPool::getThreadCount() --- src/test/ThreadPoolTest.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/ThreadPoolTest.cpp b/src/test/ThreadPoolTest.cpp index 31c8529..d5ca0d3 100644 --- a/src/test/ThreadPoolTest.cpp +++ b/src/test/ThreadPoolTest.cpp @@ -66,3 +66,14 @@ TEST(ECThreadPool, Simple) { ASSERT_EQ(data.load(), 11); } + +TEST(ECThreadPool, QueryCount) { + { + OneThreadPool oneP; + ASSERT_EQ(1, oneP.getThreadCount()); + } + { + ThreeThreadPool threeP; + ASSERT_EQ(3, threeP.getThreadCount()); + } +} From 222fbb08626060cfb39e57bec76c1aa0af7aee0c Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 7 Sep 2021 20:24:47 +0900 Subject: [PATCH 3/3] Make ThreadPool::getThreadCount() constexpr --- src/EC/ThreadPool.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EC/ThreadPool.hpp b/src/EC/ThreadPool.hpp index d3808ec..3b68c6b 100644 --- a/src/EC/ThreadPool.hpp +++ b/src/EC/ThreadPool.hpp @@ -175,7 +175,7 @@ public: /*! \brief Returns the ThreadCount that this class was created with. */ - unsigned int getThreadCount() { + constexpr unsigned int getThreadCount() { return SIZE; }