mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-30 02:32:46 +01:00
atomic_ops: Implement AtomicLoad128
This commit is contained in:
parent
7f1e66e94b
commit
b4746529e1
1 changed files with 17 additions and 0 deletions
|
@ -46,6 +46,13 @@ namespace Common {
|
||||||
reinterpret_cast<__int64*>(expected.data())) != 0;
|
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
|
#else
|
||||||
|
|
||||||
[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u8* pointer, u8 value, u8 expected) {
|
[[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);
|
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
|
#endif
|
||||||
|
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
|
Loading…
Reference in a new issue