summaryrefslogtreecommitdiffstats
path: root/src/common/atomic_ops.h
diff options
context:
space:
mode:
authorMerry <git@mary.rs>2022-03-29 00:05:54 +0200
committermerry <git@mary.rs>2022-04-02 21:55:36 +0200
commitb4746529e15daabd24ce4a8e07cf033f2802f345 (patch)
treebe4b22f86d88284e9e35f9ac12e7937e42ee9fc1 /src/common/atomic_ops.h
parentMerge pull request #8134 from Tachi107/remove-time-stretcher (diff)
downloadyuzu-b4746529e15daabd24ce4a8e07cf033f2802f345.tar
yuzu-b4746529e15daabd24ce4a8e07cf033f2802f345.tar.gz
yuzu-b4746529e15daabd24ce4a8e07cf033f2802f345.tar.bz2
yuzu-b4746529e15daabd24ce4a8e07cf033f2802f345.tar.lz
yuzu-b4746529e15daabd24ce4a8e07cf033f2802f345.tar.xz
yuzu-b4746529e15daabd24ce4a8e07cf033f2802f345.tar.zst
yuzu-b4746529e15daabd24ce4a8e07cf033f2802f345.zip
Diffstat (limited to 'src/common/atomic_ops.h')
-rw-r--r--src/common/atomic_ops.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/common/atomic_ops.h b/src/common/atomic_ops.h
index b94d73c7a..b963e7b99 100644
--- a/src/common/atomic_ops.h
+++ b/src/common/atomic_ops.h
@@ -46,6 +46,13 @@ namespace Common {
reinterpret_cast<__int64*>(expected.data())) != 0;
}
+[[nodiscard]] inline u128 AtomicLoad128(volatile u64* pointer) {
+ u128 result{};
+ _InterlockedCompareExchange128(reinterpret_cast<volatile __int64*>(pointer), result[1],
+ result[0], reinterpret_cast<__int64*>(result.data()));
+ return result;
+}
+
#else
[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u8* pointer, u8 value, u8 expected) {
@@ -72,6 +79,16 @@ namespace Common {
return __sync_bool_compare_and_swap((unsigned __int128*)pointer, expected_a, value_a);
}
+[[nodiscard]] inline u128 AtomicLoad128(volatile u64* pointer) {
+ unsigned __int128 zeros_a = 0;
+ unsigned __int128 result_a =
+ __sync_val_compare_and_swap((unsigned __int128*)pointer, zeros_a, zeros_a);
+
+ u128 result;
+ std::memcpy(result.data(), &result_a, sizeof(u128));
+ return result;
+}
+
#endif
} // namespace Common