ATLAS Offline Software
Loading...
Searching...
No Matches
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
29namespace CxxUtils {
30
31
40template <class T>
41inline
42T 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
61template <class T>
62inline
63T 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
static Double_t a
void stall()
Emit stall instruction for use in a spin loop.
Definition stall.h:37
T atomic_fetch_max(std::atomic< T > *a, T v, std::memory_order memorder=std::memory_order_seq_cst)
Atomically calculate maximum.
T atomic_fetch_min(std::atomic< T > *a, T v, std::memory_order memorder=std::memory_order_seq_cst)
Atomically calculate minimum.
Emit stall instruction for use in a spin loop.