ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.UserSettingsSupport/Interlocked.cs
Revision: 722
Committed: Tue Jun 18 19:18:05 2013 UTC (10 years, 5 months ago) by william
File size: 5191 byte(s)
Log Message:

File Contents

# User Rev Content
1 william 722 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using System.Runtime.ConstrainedExecution;
6     using System.Runtime.CompilerServices;
7     using System.Runtime;
8     using System.Runtime.InteropServices;
9     using System.Security;
10    
11     namespace RomCheater.UserSettingsSupport
12     {
13     [SecuritySafeCritical]
14     public static class Interlocked
15     {
16     // Methods
17     [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
18     public static int Add(ref int location1, int value)
19     {
20     return location1 = location1 + value;
21     }
22    
23     [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
24     public static long Add(ref long location1, long value)
25     {
26     return location1 = location1 + value;
27     }
28    
29     [MethodImpl(MethodImplOptions.InternalCall), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
30     public static extern int CompareExchange(ref int location1, int value, int comparand);
31     [ComVisible(false), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
32     public static T CompareExchange<T>(ref T location1, T value, T comparand) where T: class
33     {
34     T location1_original_value = location1;
35     location1 = (location1 == comparand) ? value : location1;
36     return location1_original_value;
37     }
38    
39     [MethodImpl(MethodImplOptions.InternalCall)]
40     public static extern double CompareExchange(ref double location1, double value, double comparand);
41     [MethodImpl(MethodImplOptions.InternalCall)]
42     public static extern long CompareExchange(ref long location1, long value, long comparand);
43     [MethodImpl(MethodImplOptions.InternalCall), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
44     public static extern IntPtr CompareExchange(ref IntPtr location1, IntPtr value, IntPtr comparand);
45     [MethodImpl(MethodImplOptions.InternalCall), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
46     public static extern object CompareExchange(ref object location1, object value, object comparand);
47     [MethodImpl(MethodImplOptions.InternalCall)]
48     public static extern float CompareExchange(ref float location1, float value, float comparand);
49     [MethodImpl(MethodImplOptions.InternalCall), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
50     internal static extern int CompareExchange(ref int location1, int value, int comparand, ref bool succeeded);
51     [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries"), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
52     public static int Decrement(ref int location)
53     {
54     return location--;
55     }
56    
57     [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
58     public static long Decrement(ref long location)
59     {
60     return location--;
61     }
62    
63     [MethodImpl(MethodImplOptions.InternalCall)]
64     public static extern double Exchange(ref double location1, double value);
65     [MethodImpl(MethodImplOptions.InternalCall), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
66     public static extern int Exchange(ref int location1, int value);
67     [MethodImpl(MethodImplOptions.InternalCall)]
68     public static extern long Exchange(ref long location1, long value);
69     [MethodImpl(MethodImplOptions.InternalCall), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
70     public static extern IntPtr Exchange(ref IntPtr location1, IntPtr value);
71     [MethodImpl(MethodImplOptions.InternalCall), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
72     public static extern object Exchange(ref object location1, object value);
73     [MethodImpl(MethodImplOptions.InternalCall)]
74     public static extern float Exchange(ref float location1, float value);
75     [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), ComVisible(false)]
76     public static T Exchange<T>(ref T location1, T value) where T: class
77     {
78     return location1 = value;
79     }
80    
81     [MethodImpl(MethodImplOptions.InternalCall), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
82     internal static extern int ExchangeAdd(ref int location1, int value);
83     [MethodImpl(MethodImplOptions.InternalCall)]
84     internal static extern long ExchangeAdd(ref long location1, long value);
85     [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
86     public static int Increment(ref int location)
87     {
88     return location++;
89     }
90    
91     [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
92     public static long Increment(ref long location)
93     {
94     return location++;
95     }
96    
97     public static long Read(ref long location)
98     {
99     return location;
100     }
101     }
102    
103    
104     }