40 return m_current_state.load(std::memory_order::seq_cst) == State::Disposed;
43 void dispose_impl(interface_disposable::Mode mode)
noexcept final
47 State expected{State::None};
49 if (m_current_state.compare_exchange_strong(expected, State::Disposed, std::memory_order::seq_cst))
51 composite_dispose_impl(mode);
53 m_disposables.dispose();
54 m_disposables.clear();
58 if (expected == State::Disposed)
63 using interface_composite_disposable::add;
67 if (disposable.is_disposed() || disposable.lock().get() ==
this)
72 State expected{State::None};
74 if (m_current_state.compare_exchange_strong(expected, State::Edit, std::memory_order::seq_cst))
78 m_disposables.push_back(std::move(disposable));
82 m_current_state.store(State::None, std::memory_order::seq_cst);
86 m_current_state.store(State::None, std::memory_order::seq_cst);
90 if (expected == State::Disposed)
102 State expected{State::None};
104 if (m_current_state.compare_exchange_strong(expected, State::Edit, std::memory_order::seq_cst))
108 m_disposables.remove(disposable);
112 m_current_state.store(State::None, std::memory_order::seq_cst);
116 m_current_state.store(State::None, std::memory_order::seq_cst);
120 if (expected == State::Disposed)
125 void clear()
override
129 State expected{State::None};
131 if (m_current_state.compare_exchange_strong(expected, State::Edit, std::memory_order::seq_cst))
135 m_disposables.dispose();
136 m_disposables.clear();
140 m_current_state.store(State::None, std::memory_order::seq_cst);
144 m_current_state.store(State::None, std::memory_order::seq_cst);
148 if (expected == State::Disposed)
154 virtual void composite_dispose_impl(interface_disposable::Mode)
noexcept {}
157 enum class State : uint8_t
164 Container m_disposables{};
165 std::atomic<State> m_current_state{};