Coverage Report

Created: 2024-11-29 06:10

/src/botan/build/include/internal/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
   public:
26
      Atomic() = default;
27
28
      Atomic(const Atomic& data) : m_data(data.m_data.load()) {}
29
30
0
      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
0
      operator std::atomic<T>&() { return m_data; }
47
48
0
      operator T() { return m_data.load(); }
49
50
   private:
51
      std::atomic<T> m_data;
52
};
53
54
}  // namespace Botan
55
56
#endif