Volatile.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. using System.Runtime.ConstrainedExecution;
  27. using System.Runtime.CompilerServices;
  28. namespace System.Threading
  29. {
  30. public
  31. 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 T Read<T> (ref T location) where T : class;
  80. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  81. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  82. public extern static void Write (ref bool location, bool value);
  83. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  84. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  85. public extern static void Write (ref byte location, byte value);
  86. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  87. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  88. [CLSCompliant (false)]
  89. public extern static void Write (ref sbyte location, sbyte value);
  90. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  91. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  92. public extern static void Write (ref short location, short value);
  93. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  94. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  95. [CLSCompliant (false)]
  96. public extern static void Write (ref ushort location, ushort value);
  97. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  98. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  99. public extern static void Write (ref int location, int value);
  100. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  101. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  102. [CLSCompliant (false)]
  103. public extern static void Write (ref uint location, uint value);
  104. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  105. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  106. public extern static void Write (ref long location, long value);
  107. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  108. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  109. [CLSCompliant (false)]
  110. public extern static void Write (ref ulong location, ulong value);
  111. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  112. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  113. public extern static void Write (ref IntPtr location, IntPtr value);
  114. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  115. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  116. [CLSCompliant (false)]
  117. public extern static void Write (ref UIntPtr location, UIntPtr value);
  118. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  119. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  120. public extern static void Write (ref double location, double value);
  121. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  122. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  123. public extern static void Write (ref float location, float value);
  124. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  125. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  126. public extern static void Write<T>(ref T location, T value) where T : class;
  127. }
  128. }