aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/threading/atomic/bool.h
blob: ec8f75427b4fc33fe21a078b856ec690dbd5e153 (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
#pragma once 
 
#include <util/system/atomic.h>
 
namespace NAtomic {
    class TBool {
    public:
        TBool() noexcept = default;

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

        TBool(const TBool& src) noexcept {
            AtomicSet(Val_, AtomicGet(src.Val_));
        }

        operator bool() const noexcept {
            return AtomicGet(Val_);
        }

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

        const TBool& operator=(const TBool& src) noexcept { 
            AtomicSet(Val_, AtomicGet(src.Val_));
            return *this;
        }

    private:
        TAtomic Val_ = 0;
    };
}