ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
CxxUtils
CxxUtils
CachedPointer.h
Go to the documentation of this file.
1
// This file's extension implies that it's C, but it's really -*- C++ -*-.
2
/*
3
* Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
4
*/
11
12
13
#ifndef CXXUTILS_CACHEDPOINTER_H
14
#define CXXUTILS_CACHEDPOINTER_H
15
16
17
#include <atomic>
18
#include <cassert>
19
20
21
#if ATOMIC_POINTER_LOCK_FREE != 2
22
# error Code assumes lock-free atomic pointers; see comments below.
23
#endif
24
25
26
namespace
CxxUtils
{
27
55
template
<
class
T>
56
union
CachedPointer
57
{
58
public
:
60
typedef
const
T*
pointer_t
;
61
62
64
CachedPointer
();
65
66
68
CachedPointer
(
pointer_t
elt);
69
70
72
CachedPointer
(
const
CachedPointer
& other)
noexcept
;
73
74
76
CachedPointer
&
operator=
(
const
CachedPointer
& other)
noexcept
;
77
78
80
void
set
(
pointer_t
elt)
const
;
81
82
84
void
store
(
pointer_t
elt);
85
86
88
pointer_t
get
()
const
;
89
90
92
const
pointer_t
*
ptr
()
const
;
93
94
95
private
:
98
mutable
std::atomic<pointer_t>
m_a
;
99
pointer_t
m_e
;
100
};
101
102
}
// namespace CxxUtils
103
104
105
#include "
CxxUtils/CachedPointer.icc
"
106
107
108
#endif
// not CXXUTILS_CACHEDPOINTER_H
CachedPointer.icc
CxxUtils
Definition
aligned_vector.h:29
CxxUtils::CachedPointer::operator=
CachedPointer & operator=(const CachedPointer &other) noexcept
Assignment.
CxxUtils::CachedPointer::set
void set(pointer_t elt) const
Set the element, assuming it is currently null.
CxxUtils::CachedPointer::get
pointer_t get() const
Return the current value of the element.
CxxUtils::CachedPointer::m_e
pointer_t m_e
Transient.
Definition
CachedPointer.h:99
CxxUtils::CachedPointer::CachedPointer
CachedPointer()
Default constructor. Sets the element to null.
CxxUtils::CachedPointer::pointer_t
const T * pointer_t
The stored pointer type.
Definition
CachedPointer.h:60
CxxUtils::CachedPointer::CachedPointer
CachedPointer(pointer_t elt)
Constructor from an element.
CxxUtils::CachedPointer::m_a
std::atomic< pointer_t > m_a
The cached element, both directly and as an atomic (recall that this is a union).
Definition
CachedPointer.h:98
CxxUtils::CachedPointer::ptr
const pointer_t * ptr() const
Return a pointer to the cached element.
CxxUtils::CachedPointer::CachedPointer
CachedPointer(const CachedPointer &other) noexcept
Copy constructor.
CxxUtils::CachedPointer::store
void store(pointer_t elt)
Store a new value to the element.
Generated on
for ATLAS Offline Software by
1.17.0