ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
CxxUtils
CxxUtils
atomic_fetch_minmax.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-2026 CERN for the benefit of the ATLAS collaboration.
4
*/
13
14
15
#ifndef CXXUTILS_ATOMIC_FETCH_MINMAX_H
16
#define CXXUTILS_ATOMIC_FETCH_MINMAX_H
17
18
19
#include "
CxxUtils/stall.h
"
20
#include <atomic>
21
22
23
namespace
CxxUtils
{
24
25
26
#if __cpp_lib_atomic_min_max
27
28
29
// As of C++26, these are available in stdlib.
30
31
32
using
std::atomic_fetch_min;
33
using
std::atomic_fetch_max;
34
35
36
#else
37
38
47
template
<
class
T>
48
inline
49
T
atomic_fetch_max
(std::atomic<T>*
a
, T v,
50
std::memory_order memorder = std::memory_order_seq_cst)
51
{
52
T orig =
a
->load (memorder);
53
while
(v > orig && !
a
->compare_exchange_strong (orig, v, memorder)) {
54
CxxUtils::stall();
55
}
56
return
orig;
57
}
58
59
68
template
<
class
T>
69
inline
70
T
atomic_fetch_min
(std::atomic<T>*
a
, T v,
71
std::memory_order memorder = std::memory_order_seq_cst)
72
{
73
T orig =
a
->load (memorder);
74
while
(v < orig && !a->compare_exchange_strong (orig, v, memorder)) {
75
CxxUtils::stall();
76
}
77
return
orig;
78
}
79
80
81
#endif
82
83
84
}
// namespace CxxUtils
85
86
87
#endif
// not CXXUTILS_ATOMIC_FETCH_MINMAX_H
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
CxxUtils
Definition
aligned_vector.h:29
CxxUtils::atomic_fetch_max
T atomic_fetch_max(std::atomic< T > *a, T v, std::memory_order memorder=std::memory_order_seq_cst)
Atomically calculate maximum.
Definition
atomic_fetch_minmax.h:49
CxxUtils::atomic_fetch_min
T atomic_fetch_min(std::atomic< T > *a, T v, std::memory_order memorder=std::memory_order_seq_cst)
Atomically calculate minimum.
Definition
atomic_fetch_minmax.h:70
stall.h
Emit stall instruction for use in a spin loop.
Generated on
for ATLAS Offline Software by
1.17.0