Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Interlocked.cs
Go to the documentation of this file.
5
6namespace System.Threading;
7
8public static class Interlocked
9{
10 public static int Increment(ref int location)
11 {
12 return Add(ref location, 1);
13 }
14
15 public static long Increment(ref long location)
16 {
17 return Add(ref location, 1L);
18 }
19
20 public static int Decrement(ref int location)
21 {
22 return Add(ref location, -1);
23 }
24
25 public static long Decrement(ref long location)
26 {
27 return Add(ref location, -1L);
28 }
29
30 [MethodImpl(MethodImplOptions.InternalCall)]
31 [Intrinsic]
32 public static extern int Exchange(ref int location1, int value);
33
34 [MethodImpl(MethodImplOptions.InternalCall)]
35 public static extern long Exchange(ref long location1, long value);
36
37 [MethodImpl(MethodImplOptions.InternalCall)]
38 public static extern float Exchange(ref float location1, float value);
39
40 [MethodImpl(MethodImplOptions.InternalCall)]
41 public static extern double Exchange(ref double location1, double value);
42
43 [MethodImpl(MethodImplOptions.InternalCall)]
44 [return: NotNullIfNotNull("location1")]
45 public static extern object? Exchange([NotNullIfNotNull("value")] ref object? location1, object? value);
46
47 [MethodImpl(MethodImplOptions.AggressiveInlining)]
48 [return: NotNullIfNotNull("location1")]
49 public static T Exchange<T>([NotNullIfNotNull("value")] ref T location1, T value) where T : class?
50 {
51 return Unsafe.As<T>(Exchange(ref Unsafe.As<T, object>(ref location1), value));
52 }
53
54 [MethodImpl(MethodImplOptions.InternalCall)]
55 [Intrinsic]
56 public static extern int CompareExchange(ref int location1, int value, int comparand);
57
58 [MethodImpl(MethodImplOptions.InternalCall)]
59 public static extern long CompareExchange(ref long location1, long value, long comparand);
60
61 [MethodImpl(MethodImplOptions.InternalCall)]
62 public static extern float CompareExchange(ref float location1, float value, float comparand);
63
64 [MethodImpl(MethodImplOptions.InternalCall)]
65 public static extern double CompareExchange(ref double location1, double value, double comparand);
66
67 [MethodImpl(MethodImplOptions.InternalCall)]
68 [return: NotNullIfNotNull("location1")]
69 public static extern object? CompareExchange(ref object? location1, object? value, object? comparand);
70
71 [Intrinsic]
72 [return: NotNullIfNotNull("location1")]
73 public static T CompareExchange<T>(ref T location1, T value, T comparand) where T : class?
74 {
75 return Unsafe.As<T>(CompareExchange(ref Unsafe.As<T, object>(ref location1), value, comparand));
76 }
77
78 public static int Add(ref int location1, int value)
79 {
80 return ExchangeAdd(ref location1, value) + value;
81 }
82
83 public static long Add(ref long location1, long value)
84 {
85 return ExchangeAdd(ref location1, value) + value;
86 }
87
88 [MethodImpl(MethodImplOptions.InternalCall)]
89 [Intrinsic]
90 private static extern int ExchangeAdd(ref int location1, int value);
91
92 [MethodImpl(MethodImplOptions.InternalCall)]
93 private static extern long ExchangeAdd(ref long location1, long value);
94
95 public static long Read(ref long location)
96 {
97 return CompareExchange(ref location, 0L, 0L);
98 }
99
100 [MethodImpl(MethodImplOptions.InternalCall)]
101 [Intrinsic]
102 public static extern void MemoryBarrier();
103
104 [MethodImpl(MethodImplOptions.InternalCall)]
105 [Intrinsic]
106 internal static extern void ReadMemoryBarrier();
107
108 [DllImport("QCall", CharSet = CharSet.Unicode)]
109 private static extern void _MemoryBarrierProcessWide();
110
111 public static void MemoryBarrierProcessWide()
112 {
114 }
115
116 [MethodImpl(MethodImplOptions.AggressiveInlining)]
117 [CLSCompliant(false)]
118 public static uint Increment(ref uint location)
119 {
120 return Add(ref location, 1u);
121 }
122
123 [MethodImpl(MethodImplOptions.AggressiveInlining)]
124 [CLSCompliant(false)]
125 public static ulong Increment(ref ulong location)
126 {
127 return Add(ref location, 1uL);
128 }
129
130 [MethodImpl(MethodImplOptions.AggressiveInlining)]
131 [CLSCompliant(false)]
132 public static uint Decrement(ref uint location)
133 {
134 return (uint)Add(ref Unsafe.As<uint, int>(ref location), -1);
135 }
136
137 [MethodImpl(MethodImplOptions.AggressiveInlining)]
138 [CLSCompliant(false)]
139 public static ulong Decrement(ref ulong location)
140 {
141 return (ulong)Add(ref Unsafe.As<ulong, long>(ref location), -1L);
142 }
143
144 [MethodImpl(MethodImplOptions.AggressiveInlining)]
145 [CLSCompliant(false)]
146 public static uint Exchange(ref uint location1, uint value)
147 {
148 return (uint)Exchange(ref Unsafe.As<uint, int>(ref location1), (int)value);
149 }
150
151 [MethodImpl(MethodImplOptions.AggressiveInlining)]
152 [CLSCompliant(false)]
153 public static ulong Exchange(ref ulong location1, ulong value)
154 {
155 return (ulong)Exchange(ref Unsafe.As<ulong, long>(ref location1), (long)value);
156 }
157
158 [MethodImpl(MethodImplOptions.AggressiveInlining)]
159 public static IntPtr Exchange(ref IntPtr location1, IntPtr value)
160 {
161 return (IntPtr)Exchange(ref Unsafe.As<IntPtr, long>(ref location1), (long)value);
162 }
163
164 [MethodImpl(MethodImplOptions.AggressiveInlining)]
165 [CLSCompliant(false)]
166 public static uint CompareExchange(ref uint location1, uint value, uint comparand)
167 {
168 return (uint)CompareExchange(ref Unsafe.As<uint, int>(ref location1), (int)value, (int)comparand);
169 }
170
171 [MethodImpl(MethodImplOptions.AggressiveInlining)]
172 [CLSCompliant(false)]
173 public static ulong CompareExchange(ref ulong location1, ulong value, ulong comparand)
174 {
175 return (ulong)CompareExchange(ref Unsafe.As<ulong, long>(ref location1), (long)value, (long)comparand);
176 }
177
178 [MethodImpl(MethodImplOptions.AggressiveInlining)]
179 public static IntPtr CompareExchange(ref IntPtr location1, IntPtr value, IntPtr comparand)
180 {
181 return (IntPtr)CompareExchange(ref Unsafe.As<IntPtr, long>(ref location1), (long)value, (long)comparand);
182 }
183
184 [MethodImpl(MethodImplOptions.AggressiveInlining)]
185 [CLSCompliant(false)]
186 public static uint Add(ref uint location1, uint value)
187 {
188 return (uint)Add(ref Unsafe.As<uint, int>(ref location1), (int)value);
189 }
190
191 [MethodImpl(MethodImplOptions.AggressiveInlining)]
192 [CLSCompliant(false)]
193 public static ulong Add(ref ulong location1, ulong value)
194 {
195 return (ulong)Add(ref Unsafe.As<ulong, long>(ref location1), (long)value);
196 }
197
198 [MethodImpl(MethodImplOptions.AggressiveInlining)]
199 [CLSCompliant(false)]
200 public static ulong Read(ref ulong location)
201 {
202 return CompareExchange(ref location, 0uL, 0uL);
203 }
204
205 [MethodImpl(MethodImplOptions.AggressiveInlining)]
206 [Intrinsic]
207 public static int And(ref int location1, int value)
208 {
209 int num = location1;
210 int num2;
211 while (true)
212 {
213 int value2 = num & value;
214 num2 = CompareExchange(ref location1, value2, num);
215 if (num2 == num)
216 {
217 break;
218 }
219 num = num2;
220 }
221 return num2;
222 }
223
224 [MethodImpl(MethodImplOptions.AggressiveInlining)]
225 [CLSCompliant(false)]
226 public static uint And(ref uint location1, uint value)
227 {
228 return (uint)And(ref Unsafe.As<uint, int>(ref location1), (int)value);
229 }
230
231 [MethodImpl(MethodImplOptions.AggressiveInlining)]
232 [Intrinsic]
233 public static long And(ref long location1, long value)
234 {
235 long num = location1;
236 long num2;
237 while (true)
238 {
239 long value2 = num & value;
240 num2 = CompareExchange(ref location1, value2, num);
241 if (num2 == num)
242 {
243 break;
244 }
245 num = num2;
246 }
247 return num2;
248 }
249
250 [MethodImpl(MethodImplOptions.AggressiveInlining)]
251 [CLSCompliant(false)]
252 public static ulong And(ref ulong location1, ulong value)
253 {
254 return (ulong)And(ref Unsafe.As<ulong, long>(ref location1), (long)value);
255 }
256
257 [MethodImpl(MethodImplOptions.AggressiveInlining)]
258 [Intrinsic]
259 public static int Or(ref int location1, int value)
260 {
261 int num = location1;
262 int num2;
263 while (true)
264 {
265 int value2 = num | value;
266 num2 = CompareExchange(ref location1, value2, num);
267 if (num2 == num)
268 {
269 break;
270 }
271 num = num2;
272 }
273 return num2;
274 }
275
276 [MethodImpl(MethodImplOptions.AggressiveInlining)]
277 [CLSCompliant(false)]
278 public static uint Or(ref uint location1, uint value)
279 {
280 return (uint)Or(ref Unsafe.As<uint, int>(ref location1), (int)value);
281 }
282
283 [MethodImpl(MethodImplOptions.AggressiveInlining)]
284 [Intrinsic]
285 public static long Or(ref long location1, long value)
286 {
287 long num = location1;
288 long num2;
289 while (true)
290 {
291 long value2 = num | value;
292 num2 = CompareExchange(ref location1, value2, num);
293 if (num2 == num)
294 {
295 break;
296 }
297 num = num2;
298 }
299 return num2;
300 }
301
302 [MethodImpl(MethodImplOptions.AggressiveInlining)]
303 [CLSCompliant(false)]
304 public static ulong Or(ref ulong location1, ulong value)
305 {
306 return (ulong)Or(ref Unsafe.As<ulong, long>(ref location1), (long)value);
307 }
308}
static uint Or(ref uint location1, uint value)
static long ExchangeAdd(ref long location1, long value)
static T Exchange< T >([NotNullIfNotNull("value")] ref T location1, T value)
static ulong Exchange(ref ulong location1, ulong value)
static ulong Add(ref ulong location1, ulong value)
static long And(ref long location1, long value)
static ulong Or(ref ulong location1, ulong value)
static ? object CompareExchange(ref object? location1, object? value, object? comparand)
static uint And(ref uint location1, uint value)
static float CompareExchange(ref float location1, float value, float comparand)
static int CompareExchange(ref int location1, int value, int comparand)
static uint Add(ref uint location1, uint value)
static void _MemoryBarrierProcessWide()
static IntPtr CompareExchange(ref IntPtr location1, IntPtr value, IntPtr comparand)
static ulong Read(ref ulong location)
static uint Exchange(ref uint location1, uint value)
static IntPtr Exchange(ref IntPtr location1, IntPtr value)
static float Exchange(ref float location1, float value)
static uint CompareExchange(ref uint location1, uint value, uint comparand)
static double Exchange(ref double location1, double value)
static ulong Increment(ref ulong location)
static int Exchange(ref int location1, int value)
static long CompareExchange(ref long location1, long value, long comparand)
static double CompareExchange(ref double location1, double value, double comparand)
static long Or(ref long location1, long value)
static int Decrement(ref int location)
static ulong CompareExchange(ref ulong location1, ulong value, ulong comparand)
static long Exchange(ref long location1, long value)
static long Read(ref long location)
static int Add(ref int location1, int value)
static void MemoryBarrierProcessWide()
static int Increment(ref int location)
static int ExchangeAdd(ref int location1, int value)
static long Add(ref long location1, long value)
static uint Increment(ref uint location)
static long Decrement(ref long location)
static int And(ref int location1, int value)
static ulong Decrement(ref ulong location)
static long Increment(ref long location)
static void ReadMemoryBarrier()
static int Or(ref int location1, int value)
static ? object Exchange([NotNullIfNotNull("value")] ref object? location1, object? value)
static T CompareExchange< T >(ref T location1, T value, T comparand)
static uint Decrement(ref uint location)
static ulong And(ref ulong location1, ulong value)