From b5a4074884e506a2ec3c584c34324af1ed3e4fa3 Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Sun, 5 Jan 2025 15:56:46 +1100 Subject: [PATCH 1/2] Swap to just using thread_local for thread local storage --- src/dsl/store/ThreadStore.hpp | 6 ++---- src/dsl/word/TaskScope.hpp | 5 ++--- src/threading/ReactionTask.cpp | 2 +- src/threading/ReactionTask.hpp | 3 +-- src/threading/scheduler/Pool.cpp | 3 +-- src/threading/scheduler/Pool.hpp | 2 +- 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/dsl/store/ThreadStore.hpp b/src/dsl/store/ThreadStore.hpp index 12c1ea94..60d5faae 100644 --- a/src/dsl/store/ThreadStore.hpp +++ b/src/dsl/store/ThreadStore.hpp @@ -23,8 +23,6 @@ #ifndef NUCLEAR_DSL_STORE_THREADSTORE_HPP #define NUCLEAR_DSL_STORE_THREADSTORE_HPP -#include "../../util/platform.hpp" - namespace NUClear { namespace dsl { namespace store { @@ -46,12 +44,12 @@ namespace dsl { */ template struct ThreadStore { - static ATTRIBUTE_TLS DataType* value; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + static thread_local DataType* value; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) }; template // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) - ATTRIBUTE_TLS DataType* ThreadStore::value = nullptr; + thread_local DataType* ThreadStore::value = nullptr; } // namespace store } // namespace dsl diff --git a/src/dsl/word/TaskScope.hpp b/src/dsl/word/TaskScope.hpp index 927a4d3e..b73e825d 100644 --- a/src/dsl/word/TaskScope.hpp +++ b/src/dsl/word/TaskScope.hpp @@ -24,7 +24,6 @@ #include "../../id.hpp" #include "../../threading/ReactionTask.hpp" -#include "../../util/platform.hpp" namespace NUClear { namespace dsl { @@ -93,12 +92,12 @@ namespace dsl { private: /// The current task id that is running // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) - static ATTRIBUTE_TLS NUClear::id_t current_task_id; + static thread_local NUClear::id_t current_task_id; }; // Initialise the current task id template // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) - ATTRIBUTE_TLS NUClear::id_t TaskScope::current_task_id{0}; + thread_local NUClear::id_t TaskScope::current_task_id{0}; } // namespace word } // namespace dsl diff --git a/src/threading/ReactionTask.cpp b/src/threading/ReactionTask.cpp index 151d604e..fa82635a 100644 --- a/src/threading/ReactionTask.cpp +++ b/src/threading/ReactionTask.cpp @@ -95,7 +95,7 @@ namespace threading { // Initialize our current task // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) - ATTRIBUTE_TLS ReactionTask* ReactionTask::current_task = nullptr; + thread_local ReactionTask* ReactionTask::current_task = nullptr; } // namespace threading } // namespace NUClear diff --git a/src/threading/ReactionTask.hpp b/src/threading/ReactionTask.hpp index 10979681..b559d0c9 100644 --- a/src/threading/ReactionTask.hpp +++ b/src/threading/ReactionTask.hpp @@ -32,7 +32,6 @@ #include "../util/GroupDescriptor.hpp" #include "../util/Inline.hpp" #include "../util/ThreadPoolDescriptor.hpp" -#include "../util/platform.hpp" #include "Reaction.hpp" namespace NUClear { @@ -53,7 +52,7 @@ namespace threading { class ReactionTask { private: /// The current task that is being executed by this thread (or nullptr if none is) - static ATTRIBUTE_TLS ReactionTask* current_task; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + static thread_local ReactionTask* current_task; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) public: /// Type of the functions that ReactionTasks execute diff --git a/src/threading/scheduler/Pool.cpp b/src/threading/scheduler/Pool.cpp index 08a2140f..6b8bb537 100644 --- a/src/threading/scheduler/Pool.cpp +++ b/src/threading/scheduler/Pool.cpp @@ -36,7 +36,6 @@ #include "../../message/ReactionStatistics.hpp" #include "../../threading/Reaction.hpp" #include "../../util/Inline.hpp" -#include "../../util/platform.hpp" #include "../ReactionTask.hpp" #include "CountingLock.hpp" #include "Scheduler.hpp" @@ -283,7 +282,7 @@ namespace threading { // Initialise the current pool to nullptr if it is not already // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) - ATTRIBUTE_TLS Pool* Pool::current_pool = nullptr; + thread_local Pool* Pool::current_pool = nullptr; } // namespace scheduler } // namespace threading diff --git a/src/threading/scheduler/Pool.hpp b/src/threading/scheduler/Pool.hpp index 1b80ec65..68b5e40d 100644 --- a/src/threading/scheduler/Pool.hpp +++ b/src/threading/scheduler/Pool.hpp @@ -246,7 +246,7 @@ namespace threading { std::unique_ptr pool_idle = nullptr; /// A thread local pointer to the current pool this thread is running in - static ATTRIBUTE_TLS Pool* current_pool; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + static thread_local Pool* current_pool; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) friend class Scheduler; }; From 84e3db320a56e9fe6b9464674ce9967e5bf7bc55 Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Sun, 5 Jan 2025 16:15:10 +1100 Subject: [PATCH 2/2] . --- src/threading/ReactionTask.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/threading/ReactionTask.cpp b/src/threading/ReactionTask.cpp index fa82635a..5e3eddf2 100644 --- a/src/threading/ReactionTask.cpp +++ b/src/threading/ReactionTask.cpp @@ -29,7 +29,6 @@ #include "../id.hpp" #include "../message/ReactionStatistics.hpp" -#include "../util/platform.hpp" #include "Reaction.hpp" namespace NUClear {