From a9c102298a269b772d44a5cf7de1678869eed4d9 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Wed, 4 Mar 2026 20:45:25 +0100 Subject: [PATCH] enable/disable threadpool from cmake --- CMakeLists.txt | 7 ++++++- flake.nix | 2 ++ include/config.hpp | 4 ++-- src/main.cpp | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 544c729..3ff816e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ if(POLICY CMP0167) cmake_policy(SET CMP0167 NEW) endif() +option(DISABLE_THREADPOOL "Disable additional physics threads" OFF) option(DISABLE_BACKWARD "Disable backward stacktrace printer" OFF) option(DISABLE_TRACY "Disable the Tracy profiler client" OFF) option(DISABLE_TESTS "Disable building tests" OFF) @@ -41,6 +42,10 @@ if(WIN32) list(APPEND LIBS opengl32 gdi32 winmm) endif() +if(NOT DISABLE_THREADPOOL) + list(APPEND FLAGS THREADPOOL) +endif() + if(NOT DISABLE_BACKWARD) find_package(Backward REQUIRED) @@ -127,4 +132,4 @@ if(supported) set_property(TARGET masssprings PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) else() message(STATUS "IPO / LTO not supported") -endif() \ No newline at end of file +endif() diff --git a/flake.nix b/flake.nix index 049df25..f736cb0 100644 --- a/flake.nix +++ b/flake.nix @@ -254,6 +254,7 @@ rec { ]; cmakeFlags = [ + "-DDISABLE_THREADPOOL=Off" "-DDISABLE_TRACY=On" "-DDISABLE_BACKWARD=On" "-DDISABLE_TESTS=On" @@ -307,6 +308,7 @@ rec { cmakeFlags = [ "-DCMAKE_SYSTEM_NAME=Windows" + "-DDISABLE_THREADPOOL=Off" "-DDISABLE_TRACY=On" "-DDISABLE_BACKWARD=On" "-DDISABLE_TESTS=On" diff --git a/include/config.hpp b/include/config.hpp index c718a48..aa0ca0b 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -3,12 +3,12 @@ #include -#define THREADPOOL // Enable physics threadpool // TODO: Using the octree from the last frame completely breaks the physics :/ // #define ASYNC_OCTREE // Gets set by CMake +// #define THREADPOOL // Enable physics threadpool // #define BACKWARD // Enable pretty stack traces // #define TRACY // Enable tracy profiling support @@ -93,4 +93,4 @@ constexpr Color BLOCK_COLOR = DARKBLUE; constexpr Color TARGET_BLOCK_COLOR = RED; constexpr Color WALL_COLOR = BLACK; -#endif \ No newline at end of file +#endif diff --git a/src/main.cpp b/src/main.cpp index 8b13b5c..4fd3b10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,7 +38,7 @@ auto set_pool_thread_name(size_t idx) -> void BS::this_thread::set_os_thread_name(std::format("worker-{}", idx)); } -BS::thread_pool<> threads(std::thread::hardware_concurrency() - 2, set_pool_thread_name); +BS::thread_pool<> threads(std::thread::hardware_concurrency(), set_pool_thread_name); constexpr std::optional* const> thread_pool = &threads; #else constexpr std::optional* const> thread_pool = std::nullopt; @@ -341,4 +341,4 @@ auto main(const int argc, char* argv[]) -> int }; return 1; -} \ No newline at end of file +}