Coverage Report

Created: 2020-03-26 13:53

/src/botan/build/include/botan/atomic.h
Line
Count
Source (jump to first uncovered line)
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
0
      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
0
      operator std::atomic<T>& () { return m_data; }
47
0
      operator T() { return m_data.load(); }
48
49
   private:
50
      std::atomic<T> m_data;
51
   };
52
53
}
54
55
#endif