2005-04-12 Dick Porter <dick@ximian.com>
[mono.git] / mcs / class / corlib / System.Threading / Interlocked.cs
1 //
2 // System.Threading.Interlocked.cs
3 //
4 // Author:
5 //        Patrik Torstensson (patrik.torstensson@labs2.com)
6 //   Dick Porter (dick@ximian.com)
7 //
8 // (C) Ximian, Inc.  http://www.ximian.com
9 //
10
11 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 //
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:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
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.
32 //
33
34 using System;
35 using System.Runtime.CompilerServices;
36
37 #if NET_2_0
38 using System.Runtime.ConstrainedExecution;
39 #endif
40
41 namespace System.Threading
42 {
43         public
44 #if NET_2_0
45         static
46 #else
47         sealed
48 #endif
49         class Interlocked 
50         {
51
52 #if !NET_2_0
53                 private Interlocked () {}
54 #endif
55
56 #if NET_2_0
57                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
58 #endif
59                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
60                 public extern static int CompareExchange(ref int location1, int value, int comparand);
61
62 #if NET_2_0
63                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
64 #endif
65                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
66                 public extern static object CompareExchange(ref object location1, object value, object comparand);
67
68                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
69                 public extern static float CompareExchange(ref float location1, float value, float comparand);
70
71 #if NET_2_0
72                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
73 #endif
74                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
75                 public extern static int Decrement(ref int location);
76
77                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
78                 public extern static long Decrement(ref long location);
79
80 #if NET_2_0
81                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
82 #endif
83                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
84                 public extern static int Increment(ref int location);
85
86                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
87                 public extern static long Increment(ref long location);
88
89 #if NET_2_0
90                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
91 #endif
92                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
93                 public extern static int Exchange(ref int location1, int value);
94
95 #if NET_2_0
96                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
97 #endif
98                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
99                 public extern static object Exchange(ref object location1, object value);
100
101                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
102                 public extern static float Exchange(ref float location1, float value);
103
104 #if NET_2_0
105                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
106                 public extern static long CompareExchange(ref long location1, long value, long comparand);
107
108                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
109                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
110                 public extern static IntPtr CompareExchange(ref IntPtr location1, IntPtr value, IntPtr comparand);
111
112                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
113                 public extern static double CompareExchange(ref double location1, double value, double comparand);
114
115                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
116                 public extern static long Exchange(ref long location1, long value);
117
118                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]
119                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
120                 public extern static IntPtr Exchange(ref IntPtr location1, IntPtr value);
121
122                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
123                 public extern static double Exchange(ref double location1, double value);
124
125                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
126                 public extern static long Read(ref long location1);
127
128                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, CER.Success)]           
129                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
130                 public extern static int Add(ref int location1, int add);
131
132                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
133                 public extern static long Add(ref long location1, long add);
134 #endif
135         }
136 }
137