summaryrefslogtreecommitdiff
path: root/src/common/atomic_ops.h
diff options
context:
space:
mode:
authorGravatar Merry2024-01-27 21:36:39 +0000
committerGravatar Merry2024-01-27 21:36:39 +0000
commit9f91d310c6a79bb0f5f681e931edf29158895311 (patch)
treefff7a04ba918c76c8631755f34ec02d656ab4d43 /src/common/atomic_ops.h
parentatomic_ops: Reduce code duplication with templates (diff)
downloadyuzu-9f91d310c6a79bb0f5f681e931edf29158895311.tar.gz
yuzu-9f91d310c6a79bb0f5f681e931edf29158895311.tar.xz
yuzu-9f91d310c6a79bb0f5f681e931edf29158895311.zip
atomic_ops: Remove volatile qualifier
Diffstat (limited to '')
-rw-r--r--src/common/atomic_ops.h40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/common/atomic_ops.h b/src/common/atomic_ops.h
index c809e6963..885fe3c4e 100644
--- a/src/common/atomic_ops.h
+++ b/src/common/atomic_ops.h
@@ -16,32 +16,31 @@ namespace Common {
16#if _MSC_VER 16#if _MSC_VER
17 17
18template <typename T> 18template <typename T>
19[[nodiscard]] inline bool AtomicCompareAndSwap(volatile T* pointer, T value, T expected); 19[[nodiscard]] inline bool AtomicCompareAndSwap(T* pointer, T value, T expected);
20template <typename T> 20template <typename T>
21[[nodiscard]] inline bool AtomicCompareAndSwap(volatile T* pointer, T value, T expected, T& actual); 21[[nodiscard]] inline bool AtomicCompareAndSwap(T* pointer, T value, T expected, T& actual);
22 22
23template [[nodiscard]] inline bool AtomicCompareAndSwap<u8>(volatile u8* pointer, u8 value, 23template [[nodiscard]] inline bool AtomicCompareAndSwap<u8>(u8* pointer, u8 value, u8 expected) {
24 u8 expected) {
25 const u8 result = 24 const u8 result =
26 _InterlockedCompareExchange8(reinterpret_cast<volatile char*>(pointer), value, expected); 25 _InterlockedCompareExchange8(reinterpret_cast<volatile char*>(pointer), value, expected);
27 return result == expected; 26 return result == expected;
28} 27}
29 28
30template [[nodiscard]] inline bool AtomicCompareAndSwap<u16>(volatile u16* pointer, u16 value, 29template [[nodiscard]] inline bool AtomicCompareAndSwap<u16>(u16* pointer, u16 value,
31 u16 expected) { 30 u16 expected) {
32 const u16 result = 31 const u16 result =
33 _InterlockedCompareExchange16(reinterpret_cast<volatile short*>(pointer), value, expected); 32 _InterlockedCompareExchange16(reinterpret_cast<volatile short*>(pointer), value, expected);
34 return result == expected; 33 return result == expected;
35} 34}
36 35
37template [[nodiscard]] inline bool AtomicCompareAndSwap<u32>(volatile u32* pointer, u32 value, 36template [[nodiscard]] inline bool AtomicCompareAndSwap<u32>(u32* pointer, u32 value,
38 u32 expected) { 37 u32 expected) {
39 const u32 result = 38 const u32 result =
40 _InterlockedCompareExchange(reinterpret_cast<volatile long*>(pointer), value, expected); 39 _InterlockedCompareExchange(reinterpret_cast<volatile long*>(pointer), value, expected);
41 return result == expected; 40 return result == expected;
42} 41}
43 42
44template [[nodiscard]] inline bool AtomicCompareAndSwap<u64>(volatile u64* pointer, u64 value, 43template [[nodiscard]] inline bool AtomicCompareAndSwap<u64>(u64* pointer, u64 value,
45 u64 expected) { 44 u64 expected) {
46 const u64 result = _InterlockedCompareExchange64(reinterpret_cast<volatile __int64*>(pointer), 45 const u64 result = _InterlockedCompareExchange64(reinterpret_cast<volatile __int64*>(pointer),
47 value, expected); 46 value, expected);
@@ -54,29 +53,29 @@ template [[nodiscard]] inline bool AtomicCompareAndSwap<u64>(volatile u64* point
54 reinterpret_cast<__int64*>(expected.data())) != 0; 53 reinterpret_cast<__int64*>(expected.data())) != 0;
55} 54}
56 55
57template [[nodiscard]] inline bool AtomicCompareAndSwap<u8>(volatile u8* pointer, u8 value, 56template [[nodiscard]] inline bool AtomicCompareAndSwap<u8>(u8* pointer, u8 value, u8 expected,
58 u8 expected, u8& actual) { 57 u8& actual) {
59 actual = 58 actual =
60 _InterlockedCompareExchange8(reinterpret_cast<volatile char*>(pointer), value, expected); 59 _InterlockedCompareExchange8(reinterpret_cast<volatile char*>(pointer), value, expected);
61 return actual == expected; 60 return actual == expected;
62} 61}
63 62
64template [[nodiscard]] inline bool AtomicCompareAndSwap<u16>(volatile u16* pointer, u16 value, 63template [[nodiscard]] inline bool AtomicCompareAndSwap<u16>(u16* pointer, u16 value, u16 expected,
65 u16 expected, u16& actual) { 64 u16& actual) {
66 actual = 65 actual =
67 _InterlockedCompareExchange16(reinterpret_cast<volatile short*>(pointer), value, expected); 66 _InterlockedCompareExchange16(reinterpret_cast<volatile short*>(pointer), value, expected);
68 return actual == expected; 67 return actual == expected;
69} 68}
70 69
71template [[nodiscard]] inline bool AtomicCompareAndSwap<u32>(volatile u32* pointer, u32 value, 70template [[nodiscard]] inline bool AtomicCompareAndSwap<u32>(u32* pointer, u32 value, u32 expected,
72 u32 expected, u32& actual) { 71 u32& actual) {
73 actual = 72 actual =
74 _InterlockedCompareExchange(reinterpret_cast<volatile long*>(pointer), value, expected); 73 _InterlockedCompareExchange(reinterpret_cast<volatile long*>(pointer), value, expected);
75 return actual == expected; 74 return actual == expected;
76} 75}
77 76
78template [[nodiscard]] inline bool AtomicCompareAndSwap<u64>(volatile u64* pointer, u64 value, 77template [[nodiscard]] inline bool AtomicCompareAndSwap<u64>(u64* pointer, u64 value, u64 expected,
79 u64 expected, u64& actual) { 78 u64& actual) {
80 actual = _InterlockedCompareExchange64(reinterpret_cast<volatile __int64*>(pointer), value, 79 actual = _InterlockedCompareExchange64(reinterpret_cast<volatile __int64*>(pointer), value,
81 expected); 80 expected);
82 return actual == expected; 81 return actual == expected;
@@ -101,11 +100,11 @@ template [[nodiscard]] inline bool AtomicCompareAndSwap<u64>(volatile u64* point
101#else 100#else
102 101
103template <typename T> 102template <typename T>
104[[nodiscard]] inline bool AtomicCompareAndSwap(volatile T* pointer, T value, T expected) { 103[[nodiscard]] inline bool AtomicCompareAndSwap(T* pointer, T value, T expected) {
105 return __sync_bool_compare_and_swap(pointer, expected, value); 104 return __sync_bool_compare_and_swap(pointer, expected, value);
106} 105}
107 106
108[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u64* pointer, u128 value, u128 expected) { 107[[nodiscard]] inline bool AtomicCompareAndSwap(u64* pointer, u128 value, u128 expected) {
109 unsigned __int128 value_a; 108 unsigned __int128 value_a;
110 unsigned __int128 expected_a; 109 unsigned __int128 expected_a;
111 std::memcpy(&value_a, value.data(), sizeof(u128)); 110 std::memcpy(&value_a, value.data(), sizeof(u128));
@@ -114,13 +113,12 @@ template <typename T>
114} 113}
115 114
116template <typename T> 115template <typename T>
117[[nodiscard]] inline bool AtomicCompareAndSwap(volatile T* pointer, T value, T expected, 116[[nodiscard]] inline bool AtomicCompareAndSwap(T* pointer, T value, T expected, T& actual) {
118 T& actual) {
119 actual = __sync_val_compare_and_swap(pointer, expected, value); 117 actual = __sync_val_compare_and_swap(pointer, expected, value);
120 return actual == expected; 118 return actual == expected;
121} 119}
122 120
123[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u64* pointer, u128 value, u128 expected, 121[[nodiscard]] inline bool AtomicCompareAndSwap(u64* pointer, u128 value, u128 expected,
124 u128& actual) { 122 u128& actual) {
125 unsigned __int128 value_a; 123 unsigned __int128 value_a;
126 unsigned __int128 expected_a; 124 unsigned __int128 expected_a;
@@ -132,7 +130,7 @@ template <typename T>
132 return actual_a == expected_a; 130 return actual_a == expected_a;
133} 131}
134 132
135[[nodiscard]] inline u128 AtomicLoad128(volatile u64* pointer) { 133[[nodiscard]] inline u128 AtomicLoad128(u64* pointer) {
136 unsigned __int128 zeros_a = 0; 134 unsigned __int128 zeros_a = 0;
137 unsigned __int128 result_a = 135 unsigned __int128 result_a =
138 __sync_val_compare_and_swap((unsigned __int128*)pointer, zeros_a, zeros_a); 136 __sync_val_compare_and_swap((unsigned __int128*)pointer, zeros_a, zeros_a);