summaryrefslogtreecommitdiffstats
path: root/library/cpp/deprecated/atomic_bool/bool.h
blob: cd9e3d32ad70888573d7a3fe219d35306d5a9e53 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once

#include <atomic>

namespace NAtomic {
    class TBool {
    public:
        TBool() noexcept = default;

        TBool(bool val) noexcept
            : Val_(val)
        {
        }

        TBool(const TBool& src) noexcept
            : Val_(src.Val_.load())
        {
        }

        operator bool() const noexcept {
            return Val_.load();
        }

        const TBool& operator=(bool val) noexcept {
            Val_.store(val);
            return *this;
        }

        const TBool& operator=(const TBool& src) noexcept {
            Val_.store(src.Val_.load());
            return *this;
        }

    private:
        std::atomic<bool> Val_ = false;
    };
} // namespace NAtomic