diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2022-06-13 13:30:13 +0200 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2022-06-13 15:39:47 +0200 |
commit | 14c6648c71b4b8a12ac0905ff23fcd4de7f0556f (patch) | |
tree | 265b9b616486e77ad69820d1fe5fc7feb088bb97 /src/buildtool/build_engine/expression/expression.cpp | |
parent | 1ad1906f2ac3f73ccf2283e4c1cc992557d91161 (diff) | |
download | justbuild-14c6648c71b4b8a12ac0905ff23fcd4de7f0556f.tar.gz |
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.
Diffstat (limited to 'src/buildtool/build_engine/expression/expression.cpp')
-rw-r--r-- | src/buildtool/build_engine/expression/expression.cpp | 11 |
1 files changed, 1 insertions, 10 deletions
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<std::string>(ComputeHash()); - hash_.notify_all(); - } - else { - hash_.wait(nullptr); - } - } - return *hash_.load(); + return hash_.SetOnceAndGet([this] { return ComputeHash(); }); } // NOLINTNEXTLINE(misc-no-recursion) |