diff options
| author | Martin Ridgers <[email protected]> | 2021-12-16 09:29:50 +0100 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2021-12-16 09:35:52 +0100 |
| commit | 04fb698644c6ced1fef16c2114234576b4219020 (patch) | |
| tree | 26a3462e3f299770f604db797fd3e5f1d1824dbe /zencore/stats.cpp | |
| parent | Only Linux has an endian.h (diff) | |
| download | zen-04fb698644c6ced1fef16c2114234576b4219020.tar.xz zen-04fb698644c6ced1fef16c2114234576b4219020.zip | |
Use a CAS loop if atomic<Floating>::fetch_add() isn't available
Diffstat (limited to 'zencore/stats.cpp')
| -rw-r--r-- | zencore/stats.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/zencore/stats.cpp b/zencore/stats.cpp index 1bb6f6de0..595c45c3f 100644 --- a/zencore/stats.cpp +++ b/zencore/stats.cpp @@ -46,7 +46,19 @@ RawEWMA::Tick(double Alpha, uint64_t Interval, uint64_t Count, bool IsInitialUpd } else { - m_Rate.fetch_add(Alpha * (InstantRate - m_Rate)); + double Delta = Alpha * (InstantRate - m_Rate); + +#if defined(__cpp_lib_atomic_float) + m_Rate.fetch_add(Delta); +#else + double Value = m_Rate.load(std::memory_order_acquire); + double Next; + do + { + Next = Value + Delta; + } + while (!m_Rate.compare_exchange_weak(Value, Next, std::memory_order_relaxed)); +#endif } } |