Botan 2.19.5 Crypto and TLS for C&

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 <botan/types.h>
12#include <atomic>
13#include <memory>
14
15//BOTAN_FUTURE_INTERNAL_HEADER(atomic.h)
16
17 namespace Botan {
18
19 template <typename T>
20/**
21 * Simple helper class to expand std::atomic with copy constructor and copy
22 * assignment operator, i.e. for use as element in a container like
23 * std::vector. The construction of instances of this wrapper is NOT atomic
24 * and needs to be properly guarded.
25 **/
26 class Atomic final
27 {
28 public:
29 Atomic() = default;
30 Atomic(const Atomic& data) : m_data(data.m_data.load()) {}
31 Atomic(const std::atomic<T>& data) : m_data(data.load()) {}
32 ~Atomic() = default;
33
34 Atomic& operator=(const Atomic& a)
35 {
36 m_data.store(a.m_data.load());
37 return *this;
38 }
39
40 Atomic& operator=(const std::atomic<T>& a)
41 {
42 m_data.store(a.load());
43 return *this;
44 }
45
46 operator std::atomic<T>& () { return m_data; }
47 operator T() { return m_data.load(); }
48
49 private:
50 std::atomic<T> m_data;
51 };
52
53}
54
55#endif
Botan::Atomic
Definition: atomic.h:27
Botan::Atomic::Atomic
Atomic()=default
Botan::Atomic::~Atomic
~Atomic()=default
Botan::Atomic::Atomic
Atomic(const std::atomic< T > &data)
Definition: atomic.h:31
Botan::Atomic::operator=
Atomic & operator=(const Atomic &a)
Definition: atomic.h:34
Botan::Atomic::operator=
Atomic & operator=(const std::atomic< T > &a)
Definition: atomic.h:40
Botan::Atomic::Atomic
Atomic(const Atomic &data)
Definition: atomic.h:30
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:29
T
fe T
Definition: ge.cpp:37
Botan
Definition: alg_id.cpp:13