Volatile.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // Volatile.cs
  3. //
  4. // Authors:
  5. // Marek Safar ([email protected])
  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. #if NET_4_5
  27. using System.Runtime.ConstrainedExecution;
  28. using System.Runtime.CompilerServices;
  29. namespace System.Threading
  30. {
  31. public static class Volatile
  32. {
  33. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  34. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  35. public extern static bool Read (ref bool location);
  36. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  37. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  38. public extern static byte Read (ref byte location);
  39. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  40. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  41. [CLSCompliant (false)]
  42. public extern static sbyte Read (ref sbyte location);
  43. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  44. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  45. public extern static short Read (ref short location);
  46. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  47. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  48. [CLSCompliant (false)]
  49. public extern static ushort Read (ref ushort location);
  50. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  51. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  52. public extern static int Read (ref int location);
  53. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  54. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  55. [CLSCompliant (false)]
  56. public extern static uint Read (ref uint location);
  57. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  58. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  59. public extern static long Read (ref long location);
  60. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  61. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  62. [CLSCompliant (false)]
  63. public extern static ulong Read (ref ulong location);
  64. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  65. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  66. public extern static IntPtr Read (ref IntPtr location);
  67. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  68. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  69. [CLSCompliant (false)]
  70. public extern static UIntPtr Read (ref UIntPtr location);
  71. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  72. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  73. public extern static double Read (ref double location);
  74. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  75. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  76. public extern static float Read (ref float location);
  77. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  78. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  79. public extern static object Read (ref object location);
  80. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  81. public extern static T Read<T> (ref T location) where T : class;
  82. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  83. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  84. public extern static void Write (ref bool location, bool value);
  85. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  86. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  87. public extern static void Write (ref byte location, byte value);
  88. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  89. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  90. [CLSCompliant (false)]
  91. public extern static void Write (ref sbyte location, sbyte value);
  92. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  93. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  94. public extern static void Write (ref short location, short value);
  95. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  96. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  97. [CLSCompliant (false)]
  98. public extern static void Write (ref ushort location, ushort value);
  99. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  100. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  101. public extern static void Write (ref int location, int value);
  102. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  103. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  104. [CLSCompliant (false)]
  105. public extern static void Write (ref uint location, uint value);
  106. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  107. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  108. public extern static void Write (ref long location, long value);
  109. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  110. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  111. [CLSCompliant (false)]
  112. public extern static void Write (ref ulong location, ulong value);
  113. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  114. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  115. public extern static void Write (ref IntPtr location, IntPtr value);
  116. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  117. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  118. [CLSCompliant (false)]
  119. public extern static void Write (ref UIntPtr location, UIntPtr value);
  120. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  121. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  122. public extern static void Write (ref double location, double value);
  123. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  124. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  125. public extern static void Write (ref float location, float value);
  126. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  127. public extern static void Write<T>(ref T location, T value) where T : class;
  128. }
  129. }
  130. #endif