ATLAS Offline Software
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$
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)) {
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)) {
69  }
70  return orig;
71 }
72 
73 
74 } // namespace CxxUtils
75 
76 
77 #endif // not CXXUTILS_ATOMIC_FETCH_MINMAX_H
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
CxxUtils::stall
void stall()
Emit stall instruction for use in a spin loop.
Definition: stall.h:37
CxxUtils
Definition: aligned_vector.h:29
stall.h
Emit stall instruction for use in a spin loop.
python.PyAthena.v
v
Definition: PyAthena.py:154
a
TList * a
Definition: liststreamerinfos.cxx:10