Merge pull request #980 from StephenMcConnel/bug-18638
[mono.git] / mcs / class / corlib / System.Threading / Volatile.cs
1 //
2 // Volatile.cs
3 //
4 // Authors:
5 //       Marek Safar (marek.safar@gmail.com)
6 //
7 // Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
26
27 using System.Runtime.ConstrainedExecution;
28 using System.Runtime.CompilerServices;
29
30 namespace System.Threading
31 {
32 #if NET_4_5
33         public
34 #endif
35         static class Volatile
36         {
37                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
38                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
39                 public extern static bool Read (ref bool location);
40
41                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
42                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
43                 public extern static byte Read (ref byte location);
44
45                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
46                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
47                 [CLSCompliant (false)]
48                 public extern static sbyte Read (ref sbyte location);
49
50                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
51                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
52                 public extern static short Read (ref short location);
53
54                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
55                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
56                 [CLSCompliant (false)]
57                 public extern static ushort Read (ref ushort location);
58
59                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
60                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
61                 public extern static int Read (ref int location);
62
63                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
64                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
65                 [CLSCompliant (false)]
66                 public extern static uint Read (ref uint location);
67
68                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
69                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
70                 public extern static long Read (ref long location);
71
72                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
73                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
74                 [CLSCompliant (false)]
75                 public extern static ulong Read (ref ulong location);
76
77                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
78                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
79                 public extern static IntPtr Read (ref IntPtr location);
80
81                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
82                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
83                 [CLSCompliant (false)]
84                 public extern static UIntPtr Read (ref UIntPtr location);
85
86                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
87                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
88                 public extern static double Read (ref double location);
89
90                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
91                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
92                 public extern static float Read (ref float location);
93
94                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
95                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
96                 public extern static T Read<T> (ref T location) where T : class;
97
98                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
99                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
100                 public extern static void Write (ref bool location, bool value);
101
102                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
103                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
104                 public extern static void Write (ref byte location, byte value);
105
106                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
107                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
108                 [CLSCompliant (false)]
109                 public extern static void Write (ref sbyte location, sbyte value);
110
111                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
112                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
113                 public extern static void Write (ref short location, short value);
114
115                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
116                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
117                 [CLSCompliant (false)]
118                 public extern static void Write (ref ushort location, ushort value);
119
120                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
121                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
122                 public extern static void Write (ref int location, int value);
123
124                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
125                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
126                 [CLSCompliant (false)]
127                 public extern static void Write (ref uint location, uint value);
128
129                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
130                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
131                 public extern static void Write (ref long location, long value);
132
133                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
134                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
135                 [CLSCompliant (false)]
136                 public extern static void Write (ref ulong location, ulong value);
137
138                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
139                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
140                 public extern static void Write (ref IntPtr location, IntPtr value);
141
142                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
143                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
144                 [CLSCompliant (false)]
145                 public extern static void Write (ref UIntPtr location, UIntPtr value);
146
147                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
148                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
149                 public extern static void Write (ref double location, double value);
150
151                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
152                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
153                 public extern static void Write (ref float location, float value);
154
155                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
156                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
157                 public extern static void Write<T>(ref T location, T value) where T : class;
158         }
159 }