Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

atomic.h
Go to the documentation of this file.
1 /*
2 * Atomic
3 * (C) 2016 Matthias Gierlings
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 **/
7
8 #ifndef BOTAN_ATOMIC_H__
9 #define BOTAN_ATOMIC_H__
10
11 #include <atomic>
12 #include <memory>
13
14 namespace Botan {
15
16 template <typename T>
17 /**
18 * Simple helper class to expand std::atomic with copy constructor and copy
19 * assignment operator, i.e. for use as element in a container like
20 * std::vector. The construction of instances of this wrapper is NOT atomic
21 * and needs to be properly guarded.
22 **/
23 class Atomic
24 {
25 public:
26 Atomic() = default;
27 Atomic(const Atomic& data) : m_data(data.m_data.load()) {}
28 Atomic(const std::atomic<T>& data) : m_data(data.load()) {}
29 ~Atomic() = default;
30
31 Atomic& operator=(const Atomic& a)
32 {
33 m_data.store(a.m_data.load());
34 return *this;
35 }
36
37 Atomic& operator=(const std::atomic<T>& a)
38 {
39 m_data.store(a.load());
40 return *this;
41 }
42
43 operator std::atomic<T>& () { return m_data; }
44 operator T() { return m_data.load(); }
45
46 private:
47 std::atomic<T> m_data;
48 };
49
50 }
51
52 #endif
Botan::Atomic::Atomic
Atomic(const Atomic &data)
Definition: atomic.h:27
Botan::Atomic::operator=
Atomic & operator=(const Atomic &a)
Definition: atomic.h:31
Botan::Atomic::operator=
Atomic & operator=(const std::atomic< T > &a)
Definition: atomic.h:37
Botan::Atomic::~Atomic
~Atomic()=default
Botan::Atomic::Atomic
Atomic()=default
Botan
Definition: alg_id.cpp:13
Botan::Atomic
Definition: atomic.h:23
Botan::Atomic::Atomic
Atomic(const std::atomic< T > &data)
Definition: atomic.h:28