summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2024-02-14 15:33:42 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2024-04-10 16:07:46 +0200
commit438a1fb7c1a6437298fed95ec440dec7cb96f815 (patch)
tree886e823c0b1828693444779a33dfa60b3c229190
parentb2ec8d5234e5b6e0a53618f3d8ae3377150836f4 (diff)
downloadjustbuild-438a1fb7c1a6437298fed95ec440dec7cb96f815.tar.gz
atomic: Fix potential race
... as any unguarded access to non-const members of the same shared_ptr instance require the use of `atomic_load` and `atomic_store`. (cherry picked from commit bda3dabe37fdde648f90ce5aa4b20d7336570cf0)
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/utils/cpp/atomic.hpp10
2 files changed, 7 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 319f0577..9e9d1166 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ Bug fixes on top of release `1.2.4`.
- `just-mr` now reports the name of the build tool correctly, even
if not called `just`.
- Taintedness of "configure" targets is now propagated correctly.
+- Missing atomic primitives added to the source code.
## Release `1.2.4` (2023-12-19)
diff --git a/src/utils/cpp/atomic.hpp b/src/utils/cpp/atomic.hpp
index fbba8b92..bc2a7865 100644
--- a/src/utils/cpp/atomic.hpp
+++ b/src/utils/cpp/atomic.hpp
@@ -106,16 +106,18 @@ class atomic_shared_ptr {
auto operator=(atomic_shared_ptr&& other) -> atomic_shared_ptr& = delete;
auto operator=(ptr_t desired) -> ptr_t { // NOLINT
std::shared_lock lock(mutex_);
- value_ = desired;
+ std::atomic_store(&value_, desired);
return desired;
}
- operator ptr_t() const { value_; } // NOLINT
+ operator ptr_t() const { return std::atomic_load(&value_); } // NOLINT
void store(ptr_t desired) {
std::shared_lock lock(mutex_);
- value_ = std::move(desired);
+ std::atomic_store(&value_, std::move(desired));
+ }
+ [[nodiscard]] auto load() const -> ptr_t {
+ return std::atomic_load(&value_);
}
- [[nodiscard]] auto load() const -> ptr_t { return value_; }
void notify_one() { cv_.notify_one(); }
void notify_all() { cv_.notify_all(); }