Coverage Report

Created: 2022-05-14 06:06

/src/botan/build/include/botan/internal/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
namespace Botan {
16
17
template <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
 **/
24
class Atomic final
25
   {
26
   public:
27
      Atomic() = default;
28
      Atomic(const Atomic& data) : m_data(data.m_data.load()) {}
29
0
      Atomic(const std::atomic<T>& data) : m_data(data.load()) {}
30
      ~Atomic() = default;
31
32
      Atomic& operator=(const Atomic& a)
33
         {
34
         m_data.store(a.m_data.load());
35
         return *this;
36
         }
37
38
      Atomic& operator=(const std::atomic<T>& a)
39
         {
40
         m_data.store(a.load());
41
         return *this;
42
         }
43
44
0
      operator std::atomic<T>& () { return m_data; }
45
0
      operator T() { return m_data.load(); }
46
47
   private:
48
      std::atomic<T> m_data;
49
   };
50
51
}
52
53
#endif