aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd
diff options
context:
space:
mode:
Diffstat (limited to 'libs/kstd')
-rw-r--r--libs/kstd/kstd/bits/shared_ptr.hpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/libs/kstd/kstd/bits/shared_ptr.hpp b/libs/kstd/kstd/bits/shared_ptr.hpp
index ce4bfb7f..f4aed34e 100644
--- a/libs/kstd/kstd/bits/shared_ptr.hpp
+++ b/libs/kstd/kstd/bits/shared_ptr.hpp
@@ -266,11 +266,18 @@ namespace kstd
: pointer(nullptr)
, control(nullptr)
{
- if (other.control != nullptr && other.control->shared_count != 0)
+ if (other.control)
{
- pointer = other.pointer;
- control = other.control;
- ++(control->shared_count);
+ auto count = other.control->shared_count.load(std::memory_order::relaxed);
+ while (count != 0 && !other.control->shared_count.compare_exchange_weak(
+ count, count + 1, std::memory_order::acquire, std::memory_order::relaxed))
+ ;
+
+ if (count != 0)
+ {
+ pointer = other.pointer;
+ control = other.control;
+ }
}
}