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-2017 CERN for the benefit of the ATLAS collaboration.
4
*/
5
// $Id$
19
20
21
#ifndef CXXUTILS_ATOMIC_FETCH_MINMAX_H
22
#define CXXUTILS_ATOMIC_FETCH_MINMAX_H
23
24
25
#include "
CxxUtils/stall.h
"
26
#include <atomic>
27
28
29
namespace
CxxUtils
{
30
31
40
template
<
class
T>
41
inline
42
T
atomic_fetch_max
(std::atomic<T>*
a
, T v,
43
std::memory_order memorder = std::memory_order_seq_cst)
44
{
45
T orig =
a
->load (memorder);
46
while
(v > orig && !
a
->compare_exchange_strong (orig, v, memorder)) {
47
CxxUtils::stall();
48
}
49
return
orig;
50
}
51
52
61
template
<
class
T>
62
inline
63
T
atomic_fetch_min
(std::atomic<T>*
a
, T v,
64
std::memory_order memorder = std::memory_order_seq_cst)
65
{
66
T orig =
a
->load (memorder);
67
while
(v < orig && !a->compare_exchange_strong (orig, v, memorder)) {
68
CxxUtils::stall();
69
}
70
return
orig;
71
}
72
73
74
}
// namespace CxxUtils
75
76
77
#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:42
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:63
stall.h
Emit stall instruction for use in a spin loop.
Generated on
for ATLAS Offline Software by
1.17.0