GteAtomicMinMax.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <GTEngineDEF.h>
11 #include <algorithm>
12 #include <atomic>
13 
14 // Implementations of atomic minimum and atomic maximum computations. These
15 // are based on std::atomic_compare_exchange_strong.
16 
17 namespace gte
18 {
19 
20 template <typename T>
21 T AtomicMin(std::atomic<T>& v0, T const& v1);
22 
23 template <typename T>
24 T AtomicMax(std::atomic<T>& v0, T const& v1);
25 
26 
27 template <typename T>
28 T AtomicMin(std::atomic<T>& v0, T const& v1)
29 {
30  T vInitial, vMin;
31  do
32  {
33  vInitial = v0;
34  vMin = std::min(vInitial, v1);
35  } while (!std::atomic_compare_exchange_strong(&v0, &vInitial, vMin));
36  return vInitial;
37 }
38 
39 template <typename T>
40 T AtomicMax(std::atomic<T>& v0, T const& v1)
41 {
42  T vInitial, vMax;
43  do
44  {
45  vInitial = v0;
46  vMax = std::max(vInitial, v1);
47  } while (!std::atomic_compare_exchange_strong(&v0, &vInitial, vMax));
48  return vInitial;
49 }
50 
51 
52 }
GLfloat GLfloat v1
Definition: glcorearb.h:812
GLfloat v0
Definition: glcorearb.h:811
T AtomicMax(std::atomic< T > &v0, T const &v1)
T AtomicMin(std::atomic< T > &v0, T const &v1)


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59