summaryrefslogtreecommitdiffstats
path: root/src/common/x64/native_clock.cpp
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2021-11-23 03:29:00 +0100
committerFernando Sahmkow <fsahmkow27@gmail.com>2022-06-28 01:06:48 +0200
commit096366ead51345bcd170e31b6160b14aaf73e996 (patch)
treedb99c0d032466f4bd94871baaecf0544fec82f25 /src/common/x64/native_clock.cpp
parentMerge pull request #8504 from comex/mesosphere-current-process (diff)
downloadyuzu-096366ead51345bcd170e31b6160b14aaf73e996.tar
yuzu-096366ead51345bcd170e31b6160b14aaf73e996.tar.gz
yuzu-096366ead51345bcd170e31b6160b14aaf73e996.tar.bz2
yuzu-096366ead51345bcd170e31b6160b14aaf73e996.tar.lz
yuzu-096366ead51345bcd170e31b6160b14aaf73e996.tar.xz
yuzu-096366ead51345bcd170e31b6160b14aaf73e996.tar.zst
yuzu-096366ead51345bcd170e31b6160b14aaf73e996.zip
Diffstat (limited to 'src/common/x64/native_clock.cpp')
-rw-r--r--src/common/x64/native_clock.cpp40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp
index 1b7194503..427a382cd 100644
--- a/src/common/x64/native_clock.cpp
+++ b/src/common/x64/native_clock.cpp
@@ -5,7 +5,6 @@
#include <chrono>
#include <thread>
-#include "common/atomic_ops.h"
#include "common/uint128.h"
#include "common/x64/native_clock.h"
@@ -65,8 +64,10 @@ NativeClock::NativeClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequen
u64 rtsc_frequency_)
: WallClock(emulated_cpu_frequency_, emulated_clock_frequency_, true), rtsc_frequency{
rtsc_frequency_} {
- time_point.inner.last_measure = FencedRDTSC();
- time_point.inner.accumulated_ticks = 0U;
+ TimePoint new_time_point{};
+ new_time_point.last_measure = FencedRDTSC();
+ new_time_point.accumulated_ticks = 0U;
+ time_point.store(new_time_point);
ns_rtsc_factor = GetFixedPoint64Factor(NS_RATIO, rtsc_frequency);
us_rtsc_factor = GetFixedPoint64Factor(US_RATIO, rtsc_frequency);
ms_rtsc_factor = GetFixedPoint64Factor(MS_RATIO, rtsc_frequency);
@@ -76,34 +77,31 @@ NativeClock::NativeClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequen
u64 NativeClock::GetRTSC() {
TimePoint new_time_point{};
- TimePoint current_time_point{};
-
- current_time_point.pack = Common::AtomicLoad128(time_point.pack.data());
+ TimePoint current_time_point = time_point.load(std::memory_order_acquire);
do {
const u64 current_measure = FencedRDTSC();
- u64 diff = current_measure - current_time_point.inner.last_measure;
+ u64 diff = current_measure - current_time_point.last_measure;
diff = diff & ~static_cast<u64>(static_cast<s64>(diff) >> 63); // max(diff, 0)
- new_time_point.inner.last_measure = current_measure > current_time_point.inner.last_measure
- ? current_measure
- : current_time_point.inner.last_measure;
- new_time_point.inner.accumulated_ticks = current_time_point.inner.accumulated_ticks + diff;
- } while (!Common::AtomicCompareAndSwap(time_point.pack.data(), new_time_point.pack,
- current_time_point.pack, current_time_point.pack));
+ new_time_point.last_measure = current_measure > current_time_point.last_measure
+ ? current_measure
+ : current_time_point.last_measure;
+ new_time_point.accumulated_ticks = current_time_point.accumulated_ticks + diff;
+ } while (!time_point.compare_exchange_weak(
+ current_time_point, new_time_point, std::memory_order_release, std::memory_order_acquire));
/// The clock cannot be more precise than the guest timer, remove the lower bits
- return new_time_point.inner.accumulated_ticks & inaccuracy_mask;
+ return new_time_point.accumulated_ticks & inaccuracy_mask;
}
void NativeClock::Pause(bool is_paused) {
if (!is_paused) {
- TimePoint current_time_point{};
TimePoint new_time_point{};
-
- current_time_point.pack = Common::AtomicLoad128(time_point.pack.data());
+ TimePoint current_time_point = time_point.load(std::memory_order_acquire);
do {
- new_time_point.pack = current_time_point.pack;
- new_time_point.inner.last_measure = FencedRDTSC();
- } while (!Common::AtomicCompareAndSwap(time_point.pack.data(), new_time_point.pack,
- current_time_point.pack, current_time_point.pack));
+ new_time_point = current_time_point;
+ new_time_point.last_measure = FencedRDTSC();
+ } while (!time_point.compare_exchange_weak(current_time_point, new_time_point,
+ std::memory_order_release,
+ std::memory_order_acquire));
}
}