Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Volatile.cs
Go to the documentation of this file.
5
6namespace System.Threading;
7
8public static class Volatile
9{
10 private struct VolatileBoolean
11 {
12 public volatile bool Value;
13 }
14
15 private struct VolatileByte
16 {
17 public volatile byte Value;
18 }
19
20 private struct VolatileInt16
21 {
22 public volatile short Value;
23 }
24
25 private struct VolatileInt32
26 {
27 public volatile int Value;
28 }
29
30 private struct VolatileIntPtr
31 {
32 public volatile IntPtr Value;
33 }
34
35 private struct VolatileSByte
36 {
37 public volatile sbyte Value;
38 }
39
40 private struct VolatileSingle
41 {
42 public volatile float Value;
43 }
44
45 private struct VolatileUInt16
46 {
47 public volatile ushort Value;
48 }
49
50 private struct VolatileUInt32
51 {
52 public volatile uint Value;
53 }
54
55 private struct VolatileUIntPtr
56 {
57 public volatile UIntPtr Value;
58 }
59
60 private struct VolatileObject
61 {
62 public volatile object Value;
63 }
64
65 [Intrinsic]
66 [NonVersionable]
67 public static bool Read(ref bool location)
68 {
69 return Unsafe.As<bool, VolatileBoolean>(ref location).Value;
70 }
71
72 [Intrinsic]
73 [NonVersionable]
74 public static void Write(ref bool location, bool value)
75 {
76 Unsafe.As<bool, VolatileBoolean>(ref location).Value = value;
77 }
78
79 [Intrinsic]
80 [NonVersionable]
81 public static byte Read(ref byte location)
82 {
83 return Unsafe.As<byte, VolatileByte>(ref location).Value;
84 }
85
86 [Intrinsic]
87 [NonVersionable]
88 public static void Write(ref byte location, byte value)
89 {
90 Unsafe.As<byte, VolatileByte>(ref location).Value = value;
91 }
92
93 [Intrinsic]
94 [NonVersionable]
95 public unsafe static double Read(ref double location)
96 {
97 long num = Read(ref Unsafe.As<double, long>(ref location));
98 return *(double*)(&num);
99 }
100
101 [Intrinsic]
102 [NonVersionable]
103 public unsafe static void Write(ref double location, double value)
104 {
105 Write(ref Unsafe.As<double, long>(ref location), *(long*)(&value));
106 }
107
108 [Intrinsic]
109 [NonVersionable]
110 public static short Read(ref short location)
111 {
112 return Unsafe.As<short, VolatileInt16>(ref location).Value;
113 }
114
115 [Intrinsic]
116 [NonVersionable]
117 public static void Write(ref short location, short value)
118 {
119 Unsafe.As<short, VolatileInt16>(ref location).Value = value;
120 }
121
122 [Intrinsic]
123 [NonVersionable]
124 public static int Read(ref int location)
125 {
126 return Unsafe.As<int, VolatileInt32>(ref location).Value;
127 }
128
129 [Intrinsic]
130 [NonVersionable]
131 public static void Write(ref int location, int value)
132 {
133 Unsafe.As<int, VolatileInt32>(ref location).Value = value;
134 }
135
136 [Intrinsic]
137 [NonVersionable]
138 public static long Read(ref long location)
139 {
140 return (long)Unsafe.As<long, VolatileIntPtr>(ref location).Value;
141 }
142
143 [Intrinsic]
144 [NonVersionable]
145 public static void Write(ref long location, long value)
146 {
147 Unsafe.As<long, VolatileIntPtr>(ref location).Value = (IntPtr)value;
148 }
149
150 [Intrinsic]
151 [NonVersionable]
152 public static IntPtr Read(ref IntPtr location)
153 {
154 return Unsafe.As<IntPtr, VolatileIntPtr>(ref location).Value;
155 }
156
157 [Intrinsic]
158 [NonVersionable]
159 public static void Write(ref IntPtr location, IntPtr value)
160 {
161 Unsafe.As<IntPtr, VolatileIntPtr>(ref location).Value = value;
162 }
163
164 [CLSCompliant(false)]
165 [Intrinsic]
166 [NonVersionable]
167 public static sbyte Read(ref sbyte location)
168 {
169 return Unsafe.As<sbyte, VolatileSByte>(ref location).Value;
170 }
171
172 [CLSCompliant(false)]
173 [Intrinsic]
174 [NonVersionable]
175 public static void Write(ref sbyte location, sbyte value)
176 {
177 Unsafe.As<sbyte, VolatileSByte>(ref location).Value = value;
178 }
179
180 [Intrinsic]
181 [NonVersionable]
182 public static float Read(ref float location)
183 {
184 return Unsafe.As<float, VolatileSingle>(ref location).Value;
185 }
186
187 [Intrinsic]
188 [NonVersionable]
189 public static void Write(ref float location, float value)
190 {
191 Unsafe.As<float, VolatileSingle>(ref location).Value = value;
192 }
193
194 [CLSCompliant(false)]
195 [Intrinsic]
196 [NonVersionable]
197 public static ushort Read(ref ushort location)
198 {
199 return Unsafe.As<ushort, VolatileUInt16>(ref location).Value;
200 }
201
202 [CLSCompliant(false)]
203 [Intrinsic]
204 [NonVersionable]
205 public static void Write(ref ushort location, ushort value)
206 {
207 Unsafe.As<ushort, VolatileUInt16>(ref location).Value = value;
208 }
209
210 [CLSCompliant(false)]
211 [Intrinsic]
212 [NonVersionable]
213 public static uint Read(ref uint location)
214 {
215 return Unsafe.As<uint, VolatileUInt32>(ref location).Value;
216 }
217
218 [CLSCompliant(false)]
219 [Intrinsic]
220 [NonVersionable]
221 public static void Write(ref uint location, uint value)
222 {
223 Unsafe.As<uint, VolatileUInt32>(ref location).Value = value;
224 }
225
226 [CLSCompliant(false)]
227 [Intrinsic]
228 [NonVersionable]
229 public static ulong Read(ref ulong location)
230 {
231 return (ulong)Read(ref Unsafe.As<ulong, long>(ref location));
232 }
233
234 [CLSCompliant(false)]
235 [Intrinsic]
236 [NonVersionable]
237 public static void Write(ref ulong location, ulong value)
238 {
239 Write(ref Unsafe.As<ulong, long>(ref location), (long)value);
240 }
241
242 [CLSCompliant(false)]
243 [Intrinsic]
244 [NonVersionable]
245 public static UIntPtr Read(ref UIntPtr location)
246 {
247 return Unsafe.As<UIntPtr, VolatileUIntPtr>(ref location).Value;
248 }
249
250 [CLSCompliant(false)]
251 [Intrinsic]
252 [NonVersionable]
253 public static void Write(ref UIntPtr location, UIntPtr value)
254 {
255 Unsafe.As<UIntPtr, VolatileUIntPtr>(ref location).Value = value;
256 }
257
258 [Intrinsic]
259 [NonVersionable]
260 [return: NotNullIfNotNull("location")]
261 public static T Read<T>([NotNullIfNotNull("location")] ref T location) where T : class?
262 {
263 return Unsafe.As<T>(Unsafe.As<T, VolatileObject>(ref location).Value);
264 }
265
266 [Intrinsic]
267 [NonVersionable]
268 public static void Write<T>([NotNullIfNotNull("value")] ref T location, T value) where T : class?
269 {
270 Unsafe.As<T, VolatileObject>(ref location).Value = value;
271 }
272}
static void Write(ref float location, float value)
Definition Volatile.cs:189
static void Write(ref long location, long value)
Definition Volatile.cs:145
static sbyte Read(ref sbyte location)
Definition Volatile.cs:167
static void Write(ref UIntPtr location, UIntPtr value)
Definition Volatile.cs:253
static bool Read(ref bool location)
Definition Volatile.cs:67
static void Write(ref bool location, bool value)
Definition Volatile.cs:74
static void Write(ref int location, int value)
Definition Volatile.cs:131
static int Read(ref int location)
Definition Volatile.cs:124
static byte Read(ref byte location)
Definition Volatile.cs:81
static T Read< T >([NotNullIfNotNull("location")] ref T location)
Definition Volatile.cs:261
static void Write(ref IntPtr location, IntPtr value)
Definition Volatile.cs:159
static void Write(ref byte location, byte value)
Definition Volatile.cs:88
static void Write< T >([NotNullIfNotNull("value")] ref T location, T value)
Definition Volatile.cs:268
static ulong Read(ref ulong location)
Definition Volatile.cs:229
static void Write(ref ushort location, ushort value)
Definition Volatile.cs:205
static long Read(ref long location)
Definition Volatile.cs:138
static ushort Read(ref ushort location)
Definition Volatile.cs:197
static float Read(ref float location)
Definition Volatile.cs:182
static UIntPtr Read(ref UIntPtr location)
Definition Volatile.cs:245
static void Write(ref short location, short value)
Definition Volatile.cs:117
static unsafe void Write(ref double location, double value)
Definition Volatile.cs:103
static IntPtr Read(ref IntPtr location)
Definition Volatile.cs:152
static void Write(ref ulong location, ulong value)
Definition Volatile.cs:237
static void Write(ref sbyte location, sbyte value)
Definition Volatile.cs:175
static void Write(ref uint location, uint value)
Definition Volatile.cs:221
static uint Read(ref uint location)
Definition Volatile.cs:213
static unsafe double Read(ref double location)
Definition Volatile.cs:95
static short Read(ref short location)
Definition Volatile.cs:110