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