NeuralEngine A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes. |

NeAtomicMinMax.h
1
11#pragma once
12
13#include <NeCoreLib.h>
14#include <algorithm>
15#include <atomic>
16
17 namespace NeuralEngine
18{
25
26 template <typename T>
27 T AtomicMin(std::atomic<T>& v0, T const& v1);
28
29 template <typename T>
30 T AtomicMax(std::atomic<T>& v0, T const& v1);
31
32
33 template <typename T>
34 T AtomicMin(std::atomic<T>& v0, T const& v1)
35 {
36 T vInitial, vMin;
37 do
38 {
39 vInitial = v0;
40 vMin = std::min(vInitial, v1);
41 } while (!std::atomic_compare_exchange_strong(&v0, &vInitial, vMin));
42 return vInitial;
43 }
44
45 template <typename T>
46 T AtomicMax(std::atomic<T>& v0, T const& v1)
47 {
48 T vInitial, vMax;
49 do
50 {
51 vInitial = v0;
52 vMax = std::max(vInitial, v1);
53 } while (!std::atomic_compare_exchange_strong(&v0, &vInitial, vMax));
54 return vInitial;
55 }
56}
NeuralEngine
Definition: NeArray2.h:18
NeuralEngine::AtomicMin
T AtomicMin(std::atomic< T > &v0, T const &v1)
Implementations of atomic minimum and atomic maximum computations. These are based on std::atomic_com...
Definition: NeAtomicMinMax.h:34