From fcefb954751dfc48ec8372d6af9ced591ec08339 Mon Sep 17 00:00:00 2001 From: Bira Date: Wed, 29 Nov 2023 21:15:28 -0500 Subject: [PATCH] Processor improvements and cleanup (#9) * helper function to get all cores * cleanup includes --- src/NUMANode.h | 1 - src/Pool.h | 2 -- src/Processor.h | 5 +++++ src/ProcessorLinux.h | 1 - src/ProcessorUnsupported.h | 2 +- src/WorkerPool.h | 1 - src/dxpool.h | 7 ++++++- test/ProcessorTest.cpp | 6 ++++++ 8 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/NUMANode.h b/src/NUMANode.h index 8d49447..975cf4c 100644 --- a/src/NUMANode.h +++ b/src/NUMANode.h @@ -1,7 +1,6 @@ #ifndef NUMA_NODE_H #define NUMA_NODE_H -#include "TypePolicies.h" #include "Core.h" #include diff --git a/src/Pool.h b/src/Pool.h index fc7a318..50f26c0 100644 --- a/src/Pool.h +++ b/src/Pool.h @@ -4,13 +4,11 @@ #include #include #include -#include #include #include "IndexHolder.h" #include "TypePolicies.h" #include "MutexIndexer.h" -#include "ConcurrentIndexer.h" #include "PoolItem.h" namespace dxpool { diff --git a/src/Processor.h b/src/Processor.h index 1b4ca40..920beec 100644 --- a/src/Processor.h +++ b/src/Processor.h @@ -15,5 +15,10 @@ using Processor = dxpool::ProcessorUnsupported; #endif +static inline auto GetAllAvailableCores() -> std::set { + Processor processor; + return processor.FindAvailableCores(); +} + } // namespace dxpool #endif \ No newline at end of file diff --git a/src/ProcessorLinux.h b/src/ProcessorLinux.h index e4baf32..a6a35d1 100644 --- a/src/ProcessorLinux.h +++ b/src/ProcessorLinux.h @@ -1,7 +1,6 @@ #ifndef PROCESSOR_LINUX_H #define PROCESSOR_LINUX_H -#include #include #include #include diff --git a/src/ProcessorUnsupported.h b/src/ProcessorUnsupported.h index a4a89ff..a44fd9a 100644 --- a/src/ProcessorUnsupported.h +++ b/src/ProcessorUnsupported.h @@ -45,7 +45,7 @@ class ProcessorUnsupported final: public ProcessorOperator { * * @return */ - auto SetThreadAffinity(const std::set& cores) const -> bool { + auto SetThreadAffinity(const std::set& cores) const -> bool override { throw PlatformUnsupportedError("not implemented for this platform"); } diff --git a/src/WorkerPool.h b/src/WorkerPool.h index 001b85b..ee6b0b0 100644 --- a/src/WorkerPool.h +++ b/src/WorkerPool.h @@ -1,7 +1,6 @@ #ifndef WORKER_POOL_H #define WORKER_POOL_H -#include #include #include #include diff --git a/src/dxpool.h b/src/dxpool.h index 1c5dd0f..21a0fce 100644 --- a/src/dxpool.h +++ b/src/dxpool.h @@ -1,3 +1,8 @@ +#ifndef DXPOOL_H +#define DXPOOL_H + #include "Pool.h" #include "WorkerPool.h" -#include "Processor.h" \ No newline at end of file +#include "Processor.h" + +#endif //DXPOOL_H \ No newline at end of file diff --git a/test/ProcessorTest.cpp b/test/ProcessorTest.cpp index 2c7bceb..8758f73 100644 --- a/test/ProcessorTest.cpp +++ b/test/ProcessorTest.cpp @@ -75,4 +75,10 @@ TEST_CASE("Processor and NUMA nodes") { // NOLINT(cppcoreguidelines-avoid-non-co REQUIRE(actualAffinity == desiredAffinity); } + + SECTION("Processor helper") { + const auto allCores = GetAllAvailableCores(); + + REQUIRE_FALSE(allCores.empty()); + } } \ No newline at end of file