tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_AtomicWrapper.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11#pragma once
12
13namespace tracktion { inline namespace engine
14{
15
16//==============================================================================
17//==============================================================================
21template<typename Type>
23{
24 static Type constrain (const Type& v)
25 {
26 return v;
27 }
28};
29
30
31//==============================================================================
32//==============================================================================
38template<typename Type, typename Constrainer = DummyConstrainer<Type>>
40{
41 //==============================================================================
43 AtomicWrapper() = default;
44
46 template<typename OtherType>
47 AtomicWrapper (const OtherType& other)
48 {
49 value.store (Constrainer::constrain (other));
50 }
51
54 {
55 value.store (other.value);
56 }
57
59 AtomicWrapper& operator= (const AtomicWrapper& other) noexcept
60 {
61 value.store (other.value);
62 return *this;
63 }
64
66 bool operator== (const AtomicWrapper& other) const noexcept
67 {
68 return value.load() == other.value.load();
69 }
70
72 bool operator!= (const AtomicWrapper& other) const noexcept
73 {
74 return value.load() != other.value.load();
75 }
76
77 //==============================================================================
79 operator juce::var() const noexcept
80 {
81 return Constrainer::constrain (value.load());
82 }
83
85 operator Type() const noexcept
86 {
87 return Constrainer::constrain (value.load());
88 }
89
90 //==============================================================================
91private:
92 std::atomic<Type> value { Type() };
93};
94
95}} // namespace tracktion { inline namespace engine
T load(T... args)
T store(T... args)
Wraps an atomic with an interface compatible with var so it can be used within CachedValues in a thre...
bool operator==(const AtomicWrapper &other) const noexcept
Compares the unerlaying value of another wrapper with this one.
bool operator!=(const AtomicWrapper &other) const noexcept
Compares the unerlaying value of another wrapper with this one.
AtomicWrapper()=default
Constructor.
AtomicWrapper(const OtherType &other)
Constructs a copy of another wrapper type.
AtomicWrapper & operator=(const AtomicWrapper &other) noexcept
Assigns another AtomicWrapper's underlying value to this one atomically.
AtomicWrapper(const AtomicWrapper &other)
Constructs a copy of another AtomicWrapper.
Dummy constrainer which should optimise away to nothing.