7#include "../utility/utility.hpp"
8#include "../macros.hpp"
13hi_export_module(hikogui.concurrency.atomic);
18hi_warning_ignore_msvc(26403);
20hi_export
namespace hi::inline
v1 {
27 auto expected = lhs.load(order);
28 while (expected < rhs) {
29 if (lhs.compare_exchange_weak(expected, rhs, order)) {
41 auto expected = lhs.load(order);
42 while (rhs < expected) {
43 if (lhs.compare_exchange_weak(expected, rhs, order)) {
53 using element_type = T;
54 using pointer = element_type *;
55 using reference = element_type &;
59 delete _pointer.load(std::memory_order_relaxed);
70 hi_return_on_self_assignment(other);
72 delete _pointer.exchange(other._pointer.exchange(
nullptr));
80 delete _pointer.exchange(
nullptr);
88 delete _pointer.exchange(other);
94 [[nodiscard]] pointer
get(std::memory_order order = std::memory_order::seq_cst)
const noexcept
96 return _pointer.load(order);
110 template<
typename... Args>
113 auto expected = _pointer.load(std::memory_order::acquire);
114 if (expected !=
nullptr) {
118 auto desired =
new element_type(std::forward<Args>(args)...);
119 if (not _pointer.compare_exchange_strong(expected, desired, std::memory_order::release, std::memory_order::acquire)) {
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
T fetch_max(std::atomic< T > &lhs, T rhs, std::memory_order order) noexcept
Lock-free fetch-then-max operation on an atomic.
Definition atomic.hpp:25
T fetch_min(std::atomic< T > &lhs, T rhs, std::memory_order order) noexcept
Lock-free fetch-then-min operation on an atomic.
Definition atomic.hpp:39
reference get_or_make(Args &&...args) noexcept
Get or make an object.
Definition atomic.hpp:111
pointer get(std::memory_order order=std::memory_order::seq_cst) const noexcept
Get the raw pointer.
Definition atomic.hpp:94