mscorlib(4.0.0.0) API with additions
Volatile.cs
2 using System.Security;
3 
4 namespace System.Threading
5 {
7  [__DynamicallyInvokable]
8  public static class Volatile
9  {
13  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
14  [__DynamicallyInvokable]
15  public static bool Read(ref bool location)
16  {
17  bool result = location;
19  return result;
20  }
21 
25  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
26  [CLSCompliant(false)]
27  [__DynamicallyInvokable]
28  public static sbyte Read(ref sbyte location)
29  {
30  sbyte result = location;
32  return result;
33  }
34 
38  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
39  [__DynamicallyInvokable]
40  public static byte Read(ref byte location)
41  {
42  byte result = location;
44  return result;
45  }
46 
50  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
51  [__DynamicallyInvokable]
52  public static short Read(ref short location)
53  {
54  short result = location;
56  return result;
57  }
58 
62  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
63  [CLSCompliant(false)]
64  [__DynamicallyInvokable]
65  public static ushort Read(ref ushort location)
66  {
67  ushort result = location;
69  return result;
70  }
71 
75  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
76  [__DynamicallyInvokable]
77  public static int Read(ref int location)
78  {
79  int result = location;
81  return result;
82  }
83 
87  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
88  [CLSCompliant(false)]
89  [__DynamicallyInvokable]
90  public static uint Read(ref uint location)
91  {
92  uint result = location;
94  return result;
95  }
96 
100  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
101  [__DynamicallyInvokable]
102  public static long Read(ref long location)
103  {
104  return Interlocked.CompareExchange(ref location, 0L, 0L);
105  }
106 
110  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
111  [CLSCompliant(false)]
112  [SecuritySafeCritical]
113  [__DynamicallyInvokable]
114  public unsafe static ulong Read(ref ulong location)
115  {
116  fixed (ulong* ptr = &location)
117  {
118  return (ulong)Interlocked.CompareExchange(ref *(long*)ptr, 0L, 0L);
119  }
120  }
121 
125  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
126  public static IntPtr Read(ref IntPtr location)
127  {
128  IntPtr result = location;
130  return result;
131  }
132 
136  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
137  [CLSCompliant(false)]
138  public static UIntPtr Read(ref UIntPtr location)
139  {
140  UIntPtr result = location;
142  return result;
143  }
144 
148  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
149  [__DynamicallyInvokable]
150  public static float Read(ref float location)
151  {
152  float result = location;
154  return result;
155  }
156 
160  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
161  [__DynamicallyInvokable]
162  public static double Read(ref double location)
163  {
164  return Interlocked.CompareExchange(ref location, 0.0, 0.0);
165  }
166 
171  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
172  [SecuritySafeCritical]
173  [__DynamicallyInvokable]
174  public static T Read<T>(ref T location) where T : class
175  {
176  T result = location;
178  return result;
179  }
180 
184  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
185  [__DynamicallyInvokable]
186  public static void Write(ref bool location, bool value)
187  {
189  location = value;
190  }
191 
195  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
196  [CLSCompliant(false)]
197  [__DynamicallyInvokable]
198  public static void Write(ref sbyte location, sbyte value)
199  {
201  location = value;
202  }
203 
207  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
208  [__DynamicallyInvokable]
209  public static void Write(ref byte location, byte value)
210  {
212  location = value;
213  }
214 
218  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
219  [__DynamicallyInvokable]
220  public static void Write(ref short location, short value)
221  {
223  location = value;
224  }
225 
229  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
230  [CLSCompliant(false)]
231  [__DynamicallyInvokable]
232  public static void Write(ref ushort location, ushort value)
233  {
235  location = value;
236  }
237 
241  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
242  [__DynamicallyInvokable]
243  public static void Write(ref int location, int value)
244  {
246  location = value;
247  }
248 
252  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
253  [CLSCompliant(false)]
254  [__DynamicallyInvokable]
255  public static void Write(ref uint location, uint value)
256  {
258  location = value;
259  }
260 
264  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
265  [__DynamicallyInvokable]
266  public static void Write(ref long location, long value)
267  {
268  Interlocked.Exchange(ref location, value);
269  }
270 
274  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
275  [CLSCompliant(false)]
276  [SecuritySafeCritical]
277  [__DynamicallyInvokable]
278  public unsafe static void Write(ref ulong location, ulong value)
279  {
280  fixed (ulong* ptr = &location)
281  {
282  Interlocked.Exchange(ref *(long*)ptr, (long)value);
283  }
284  }
285 
289  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
290  public static void Write(ref IntPtr location, IntPtr value)
291  {
293  location = value;
294  }
295 
299  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
300  [CLSCompliant(false)]
301  public static void Write(ref UIntPtr location, UIntPtr value)
302  {
304  location = value;
305  }
306 
310  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
311  [__DynamicallyInvokable]
312  public static void Write(ref float location, float value)
313  {
315  location = value;
316  }
317 
321  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
322  [__DynamicallyInvokable]
323  public static void Write(ref double location, double value)
324  {
325  Interlocked.Exchange(ref location, value);
326  }
327 
332  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
333  [SecuritySafeCritical]
334  [__DynamicallyInvokable]
335  public static void Write<T>(ref T location, T value) where T : class
336  {
338  location = value;
339  }
340  }
341 }
A platform-specific type that is used to represent a pointer or a handle.
Definition: UIntPtr.cs:14
static void Write(ref long location, long value)
Writes the specified value to the specified field. On systems that require it, inserts a memory barri...
Definition: Volatile.cs:266
static void Write(ref bool location, bool value)
Writes the specified value to the specified field. On systems that require it, inserts a memory barri...
Definition: Volatile.cs:186
static ushort Read(ref ushort location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
Definition: Volatile.cs:65
static void MemoryBarrier()
Synchronizes memory access as follows: The processor executing the current thread cannot reorder inst...
static unsafe void Write(ref ulong location, ulong value)
Writes the specified value to the specified field. On systems that require it, inserts a memory barri...
Definition: Volatile.cs:278
Definition: __Canon.cs:3
static void Write(ref ushort location, ushort value)
Writes the specified value to the specified field. On systems that require it, inserts a memory barri...
Definition: Volatile.cs:232
static void Write< T >(ref T location, T value)
Writes the specified object reference to the specified field. On systems that require it,...
Definition: Volatile.cs:335
static void Write(ref UIntPtr location, UIntPtr value)
Writes the specified value to the specified field. On systems that require it, inserts a memory barri...
Definition: Volatile.cs:301
static IntPtr Read(ref IntPtr location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
Definition: Volatile.cs:126
static int Read(ref int location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
Definition: Volatile.cs:77
static int Exchange(ref int location1, int value)
Sets a 32-bit signed integer to a specified value and returns the original value, as an atomic operat...
Cer
Specifies a method's behavior when called within a constrained execution region.
Definition: Cer.cs:5
static unsafe ulong Read(ref ulong location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
Definition: Volatile.cs:114
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
Contains methods for performing volatile memory operations.
Definition: Volatile.cs:8
static void Write(ref float location, float value)
Writes the specified value to the specified field. On systems that require it, inserts a memory barri...
Definition: Volatile.cs:312
static UIntPtr Read(ref UIntPtr location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
Definition: Volatile.cs:138
static bool Read(ref bool location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
Definition: Volatile.cs:15
static double Read(ref double location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
Definition: Volatile.cs:162
static sbyte Read(ref sbyte location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
Definition: Volatile.cs:28
static void Write(ref int location, int value)
Writes the specified value to the specified field. On systems that require it, inserts a memory barri...
Definition: Volatile.cs:243
static void Write(ref byte location, byte value)
Writes the specified value to the specified field. On systems that require it, inserts a memory barri...
Definition: Volatile.cs:209
static short Read(ref short location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
Definition: Volatile.cs:52
static void Write(ref sbyte location, sbyte value)
Writes the specified value to the specified field. On systems that require it, inserts a memory barri...
Definition: Volatile.cs:198
static uint Read(ref uint location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
Definition: Volatile.cs:90
static void Write(ref uint location, uint value)
Writes the specified value to the specified field. On systems that require it, inserts a memory barri...
Definition: Volatile.cs:255
static byte Read(ref byte location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
Definition: Volatile.cs:40
static void Write(ref IntPtr location, IntPtr value)
Writes the specified value to the specified field. On systems that require it, inserts a memory barri...
Definition: Volatile.cs:290
Consistency
Specifies a reliability contract.
Definition: Consistency.cs:5
static T Read< T >(ref T location)
Reads the object reference from the specified field. On systems that require it, inserts a memory bar...
Definition: Volatile.cs:174
static float Read(ref float location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
Definition: Volatile.cs:150
Provides atomic operations for variables that are shared by multiple threads.
Definition: Interlocked.cs:10
static void Write(ref short location, short value)
Writes the specified value to the specified field. On systems that require it, inserts a memory barri...
Definition: Volatile.cs:220
static long Read(ref long location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
Definition: Volatile.cs:102
static void Write(ref double location, double value)
Writes the specified value to the specified field. On systems that require it, inserts a memory barri...
Definition: Volatile.cs:323
Creates and controls a thread, sets its priority, and gets its status.
Definition: Thread.cs:18