From 14c6648c71b4b8a12ac0905ff23fcd4de7f0556f Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Mon, 13 Jun 2022 13:30:13 +0200 Subject: multithreading: Add AtomicValue to atomically set/get value ... and use it to replace the commonly used pattern in Expression, LinkedMap, and GitTreeEntry. Furthermore, remove assignment operators for Expression and LinkedMap as those are considered to be used in an immutable manner anyway. --- .../build_engine/expression/expression.hpp | 25 ++++++---------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'src/buildtool/build_engine/expression/expression.hpp') diff --git a/src/buildtool/build_engine/expression/expression.hpp b/src/buildtool/build_engine/expression/expression.hpp index 412de057..6acb1e0e 100644 --- a/src/buildtool/build_engine/expression/expression.hpp +++ b/src/buildtool/build_engine/expression/expression.hpp @@ -20,7 +20,7 @@ #include "src/buildtool/build_engine/expression/target_result.hpp" #include "src/buildtool/common/artifact_description.hpp" #include "src/buildtool/crypto/hash_generator.hpp" -#include "src/utils/cpp/atomic.hpp" +#include "src/buildtool/multithreading/atomic_value.hpp" #include "src/utils/cpp/hex_string.hpp" #include "src/utils/cpp/json.hpp" @@ -63,22 +63,10 @@ class Expression { Expression() noexcept = default; ~Expression() noexcept = default; - Expression(Expression const& other) noexcept - : data_{other.data_}, hash_{other.hash_.load()} {} - Expression(Expression&& other) noexcept - : data_{std::move(other.data_)}, hash_{other.hash_.load()} {} - auto operator=(Expression const& other) noexcept -> Expression& { - if (this != &other) { - data_ = other.data_; - } - hash_ = other.hash_.load(); - return *this; - } - auto operator=(Expression&& other) noexcept -> Expression& { - data_ = std::move(other.data_); - hash_ = other.hash_.load(); - return *this; - } + Expression(Expression const& other) noexcept = default; + Expression(Expression&& other) noexcept = default; + auto operator=(Expression const& other) noexcept = delete; + auto operator=(Expression&& other) noexcept = delete; template requires(IsValidType>()) @@ -256,8 +244,7 @@ class Expression { map_t> data_{none_t{}}; - mutable atomic_shared_ptr hash_{}; - mutable std::atomic hash_loading_{}; + AtomicValue hash_{}; template requires(IsValidType()) [[nodiscard]] static consteval auto GetIndexOf() -- cgit v1.2.3