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. --- src/buildtool/build_engine/expression/expression.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'src/buildtool/build_engine/expression/expression.cpp') diff --git a/src/buildtool/build_engine/expression/expression.cpp b/src/buildtool/build_engine/expression/expression.cpp index 679ebcbd..763f51f8 100644 --- a/src/buildtool/build_engine/expression/expression.cpp +++ b/src/buildtool/build_engine/expression/expression.cpp @@ -149,16 +149,7 @@ auto Expression::ToString() const -> std::string { // NOLINTNEXTLINE(misc-no-recursion) auto Expression::ToHash() const noexcept -> std::string { - if (hash_.load() == nullptr) { - if (not hash_loading_.exchange(true)) { - hash_ = std::make_shared(ComputeHash()); - hash_.notify_all(); - } - else { - hash_.wait(nullptr); - } - } - return *hash_.load(); + return hash_.SetOnceAndGet([this] { return ComputeHash(); }); } // NOLINTNEXTLINE(misc-no-recursion) -- cgit v1.2.3