ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
base_disposable.hpp
1// ReactivePlusPlus library
2//
3// Copyright Aleksey Loginov 2023 - present.
4// Distributed under the Boost Software License, Version 1.0.
5// (See accompanying file LICENSE_1_0.txt or copy at
6// https://www.boost.org/LICENSE_1_0.txt)
7//
8// Project home: https://github.com/victimsnino/ReactivePlusPlus
9//
10
11#pragma once
12
13#include <rpp/disposables/fwd.hpp>
14
15#include <rpp/disposables/interface_disposable.hpp>
16
17#include <atomic>
18
19namespace rpp::details
20{
21 template<typename BaseInterface>
22 class base_disposable_impl : public BaseInterface
23 {
24 public:
25 base_disposable_impl() = default;
27 base_disposable_impl(base_disposable_impl&&) noexcept = delete;
28
29 bool is_disposed() const noexcept final
30 {
31 // just need atomicity, not guarding anything
32 return m_disposed.load(std::memory_order::seq_cst);
33 }
34
35 private:
36 void dispose_impl(interface_disposable::Mode mode) noexcept final
37 {
38 // just need atomicity, not guarding anything
39 if (m_disposed.exchange(true, std::memory_order::seq_cst) == false)
40 base_dispose_impl(mode);
41 }
42
43 protected:
44 virtual void base_dispose_impl(interface_disposable::Mode) noexcept {};
45
46 private:
47 std::atomic_bool m_disposed{};
48 };
49
52} // namespace rpp::details
Definition base_disposable.hpp:23