13#include <rpp/disposables/fwd.hpp>
15#include <rpp/disposables/composite_disposable.hpp>
16#include <rpp/disposables/details/base_disposable.hpp>
17#include <rpp/disposables/disposable_wrapper.hpp>
24 class refocunt_disposable_inner;
35 auto current_value = m_refcount.load(std::memory_order::seq_cst);
36 while (current_value != s_disposed)
38 const size_t new_value = current_value == 1 ? s_disposed : current_value - 1;
39 if (!m_refcount.compare_exchange_strong(current_value, new_value, std::memory_order::seq_cst))
42 if (new_value == s_disposed)
48 void composite_dispose_impl(interface_disposable::Mode)
noexcept override
50 m_refcount.store(s_disposed, std::memory_order::seq_cst);
60 std::atomic<size_t> m_refcount{0};
61 constexpr static size_t s_disposed = std::numeric_limits<size_t>::max();
72 : m_state{std::move(state)}
76 void composite_dispose_impl(interface_disposable::Mode mode)
noexcept override
78 if (mode != interface_disposable::Mode::Destroying)
79 m_state.remove(this->wrapper_from_this());
81 if (
const auto locked = m_state.lock())
96 auto current_value = m_refcount.load(std::memory_order::seq_cst);
99 if (current_value == s_disposed)
103 if (m_refcount.compare_exchange_strong(current_value, current_value + 1, std::memory_order::seq_cst))
106 add(inner.as_weak());
Disposable which can keep some other sub-disposables. When this root disposable is disposed,...
Definition composite_disposable.hpp:175
Definition disposable_wrapper.hpp:252
Definition refcount_disposable.hpp:69
static disposable_wrapper_impl make(TArgs &&... args)
Definition disposable_wrapper.hpp:164
static disposable_wrapper_impl empty()
Creates disposable_wrapper which behaves like disposed disposable.
Definition disposable_wrapper.hpp:178
Definition refcount_disposable.hpp:31
void dispose() noexcept
Dispose disposable and free any underlying resources and etc.
Definition interface_disposable.hpp:36