diff --git a/src/dsl/word/UDP.hpp b/src/dsl/word/UDP.hpp index fb617ac7..0bff35fe 100644 --- a/src/dsl/word/UDP.hpp +++ b/src/dsl/word/UDP.hpp @@ -132,7 +132,7 @@ namespace dsl { // We can cast ourselves to a reference type so long as // that reference type is plain old data template - operator std::enable_if_t::value, const T&>() { + operator std::enable_if_t::value, const T&>() { return *reinterpret_cast(payload.data()); } }; diff --git a/src/threading/ReactionTask.hpp b/src/threading/ReactionTask.hpp index 7811e217..19473e97 100644 --- a/src/threading/ReactionTask.hpp +++ b/src/threading/ReactionTask.hpp @@ -57,7 +57,7 @@ namespace threading { public: /// Type of the functions that ReactionTasks execute - using TaskFunction = std::function; + using TaskFunction = std::function; /** * Gets the current executing task, or nullptr if there isn't one. diff --git a/src/util/TypeMap.hpp b/src/util/TypeMap.hpp index fb469685..e3c9cc42 100644 --- a/src/util/TypeMap.hpp +++ b/src/util/TypeMap.hpp @@ -58,8 +58,12 @@ namespace util { TypeMap operator=(TypeMap&& /*other*/) noexcept = delete; private: - /// The data variable where the data is stored for this map key. +/// The data variable where the data is stored for this map key. +#if __cplusplus >= 202002L + static std::atomic> data; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) +#else static std::shared_ptr data; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) +#endif public: /** @@ -68,7 +72,11 @@ namespace util { * @param d A pointer to the data to be stored (the map takes ownership) */ static void set(std::shared_ptr d) { +#if __cplusplus >= 202002L + data.store(std::move(d), std::memory_order_release); +#else std::atomic_store_explicit(&data, std::move(d), std::memory_order_release); +#endif } /** @@ -77,14 +85,23 @@ namespace util { * @return A shared_ptr to the data that was previously stored */ static std::shared_ptr get() { +#if __cplusplus >= 202002L + return data.load(std::memory_order_acquire); +#else return std::atomic_load_explicit(&data, std::memory_order_acquire); +#endif } }; /// Initialize our shared_ptr data template - std::shared_ptr - TypeMap::data; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) +#if __cplusplus >= 202002L + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) + std::atomic> TypeMap::data; +#else + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) + std::shared_ptr TypeMap::data; +#endif } // namespace util } // namespace NUClear