forked from sony/nmos-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopyable_atomic.h
More file actions
23 lines (20 loc) · 764 Bytes
/
copyable_atomic.h
File metadata and controls
23 lines (20 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef NMOS_COPYABLE_ATOMIC_H
#define NMOS_COPYABLE_ATOMIC_H
#include <atomic>
namespace nmos
{
namespace details
{
// Before using this, understand why std::atomic<T> *isn't* copyable or movable
// See e.g. https://stackoverflow.com/questions/15249998/why-are-stdatomic-objects-not-copyable
template <typename T>
struct copyable_atomic : public std::atomic<T>
{
copyable_atomic() {}
copyable_atomic(T value) : std::atomic<T>(value) {}
copyable_atomic(const copyable_atomic& other) : std::atomic<T>(other.load()) {}
copyable_atomic& operator=(const copyable_atomic& other) { if (this != &other) this->store(other.load()); return *this; }
};
}
}
#endif