2 // System.Threading.Interlocked.cs
5 // Patrik Torstensson (patrik.torstensson@labs2.com)
6 // Dick Porter (dick@ximian.com)
8 // (C) Ximian, Inc. http://www.ximian.com
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Runtime.CompilerServices;
38 using System.Runtime.ConstrainedExecution;
41 namespace System.Threading
53 private Interlocked () {}
57 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
59 [MethodImplAttribute(MethodImplOptions.InternalCall)]
60 public extern static int CompareExchange(ref int location1, int value, int comparand);
63 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
65 [MethodImplAttribute(MethodImplOptions.InternalCall)]
66 public extern static object CompareExchange(ref object location1, object value, object comparand);
68 [MethodImplAttribute(MethodImplOptions.InternalCall)]
69 public extern static float CompareExchange(ref float location1, float value, float comparand);
72 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
74 [MethodImplAttribute(MethodImplOptions.InternalCall)]
75 public extern static int Decrement(ref int location);
77 [MethodImplAttribute(MethodImplOptions.InternalCall)]
78 public extern static long Decrement(ref long location);
81 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
83 [MethodImplAttribute(MethodImplOptions.InternalCall)]
84 public extern static int Increment(ref int location);
86 [MethodImplAttribute(MethodImplOptions.InternalCall)]
87 public extern static long Increment(ref long location);
90 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
92 [MethodImplAttribute(MethodImplOptions.InternalCall)]
93 public extern static int Exchange(ref int location1, int value);
96 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
98 [MethodImplAttribute(MethodImplOptions.InternalCall)]
99 public extern static object Exchange(ref object location1, object value);
101 [MethodImplAttribute(MethodImplOptions.InternalCall)]
102 public extern static float Exchange(ref float location1, float value);
105 [MethodImplAttribute(MethodImplOptions.InternalCall)]
106 public extern static long CompareExchange(ref long location1, long value, long comparand);
108 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
109 [MethodImplAttribute(MethodImplOptions.InternalCall)]
110 public extern static IntPtr CompareExchange(ref IntPtr location1, IntPtr value, IntPtr comparand);
112 [MethodImplAttribute(MethodImplOptions.InternalCall)]
113 public extern static double CompareExchange(ref double location1, double value, double comparand);
115 [MethodImplAttribute(MethodImplOptions.InternalCall)]
116 public extern static long Exchange(ref long location1, long value);
118 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
119 [MethodImplAttribute(MethodImplOptions.InternalCall)]
120 public extern static IntPtr Exchange(ref IntPtr location1, IntPtr value);
122 [MethodImplAttribute(MethodImplOptions.InternalCall)]
123 public extern static double Exchange(ref double location1, double value);
125 [MethodImplAttribute(MethodImplOptions.InternalCall)]
126 public extern static long Read(ref long location1);
128 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
129 [MethodImplAttribute(MethodImplOptions.InternalCall)]
130 public extern static int Add(ref int location1, int add);
132 [MethodImplAttribute(MethodImplOptions.InternalCall)]
133 public extern static long Add(ref long location1, long add);