Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

080-TestSystemThreading.cs 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using System;
  2. using System.Threading;
  3. using UnityBenchShared;
  4. namespace Burst.Compiler.IL.Tests
  5. {
  6. /// <summary>
  7. /// Tests of the <see cref="System.Threading"/> functions.
  8. /// </summary>
  9. internal class TestSystemThreading
  10. {
  11. [TestCompiler]
  12. public static void TestMemoryBarrier()
  13. {
  14. Thread.MemoryBarrier();
  15. }
  16. [TestCompiler]
  17. public static int TestReadBool()
  18. {
  19. var data = false;
  20. return (Volatile.Read(ref data) ? 1 : 0) + (Volatile.Read(ref data) ? 1 : 0);
  21. }
  22. [TestCompiler((byte)42)]
  23. public static int TestReadByte(ref byte data)
  24. {
  25. return Volatile.Read(ref data) + Volatile.Read(ref data);
  26. }
  27. [TestCompiler((sbyte)42)]
  28. public static int TestReadSByte(ref sbyte data)
  29. {
  30. return Volatile.Read(ref data) + Volatile.Read(ref data);
  31. }
  32. [TestCompiler((short)42)]
  33. public static int TestReadShort(ref short data)
  34. {
  35. return Volatile.Read(ref data) + Volatile.Read(ref data);
  36. }
  37. [TestCompiler((ushort)42)]
  38. public static int TestReadUShort(ref ushort data)
  39. {
  40. return Volatile.Read(ref data) + Volatile.Read(ref data);
  41. }
  42. [TestCompiler(42)]
  43. public static int TestReadInt(ref int data)
  44. {
  45. return Volatile.Read(ref data) + Volatile.Read(ref data);
  46. }
  47. [TestCompiler(42u)]
  48. public static uint TestReadUInt(ref uint data)
  49. {
  50. return Volatile.Read(ref data) + Volatile.Read(ref data);
  51. }
  52. [TestCompiler((long)42)]
  53. public static long TestReadLong(ref long data)
  54. {
  55. return Volatile.Read(ref data) + Volatile.Read(ref data);
  56. }
  57. [TestCompiler((ulong)42)]
  58. public static ulong TestReadULong(ref ulong data)
  59. {
  60. return Volatile.Read(ref data) + Volatile.Read(ref data);
  61. }
  62. [TestCompiler(42.0f)]
  63. public static float TestReadFloat(ref float data)
  64. {
  65. return Volatile.Read(ref data);
  66. }
  67. [TestCompiler(42.0)]
  68. public static double TestReadDouble(ref double data)
  69. {
  70. return Volatile.Read(ref data);
  71. }
  72. public struct UIntPtrProvider : IArgumentProvider
  73. {
  74. public object Value => UIntPtr.Zero;
  75. }
  76. [TestCompiler(typeof(UIntPtrProvider))]
  77. public static UIntPtr TestReadUIntPtr(ref UIntPtr data)
  78. {
  79. return Volatile.Read(ref data);
  80. }
  81. [TestCompiler]
  82. public static int TestWriteBool()
  83. {
  84. var data = false;
  85. Volatile.Write(ref data, true);
  86. return data ? 1 : 0;
  87. }
  88. [TestCompiler((byte)42)]
  89. public static int TestWriteByte(ref byte data)
  90. {
  91. var result = data;
  92. Volatile.Write(ref data, 1);
  93. return result + data;
  94. }
  95. [TestCompiler((sbyte)42)]
  96. public static int TestWriteSByte(ref sbyte data)
  97. {
  98. var result = data;
  99. Volatile.Write(ref data, 2);
  100. return result + data;
  101. }
  102. [TestCompiler((short)42)]
  103. public static int TestWriteShort(ref short data)
  104. {
  105. var result = data;
  106. Volatile.Write(ref data, 3);
  107. return result + data;
  108. }
  109. [TestCompiler((ushort)42)]
  110. public static int TestWriteUShort(ref ushort data)
  111. {
  112. var result = data;
  113. Volatile.Write(ref data, 4);
  114. return result + data;
  115. }
  116. [TestCompiler(42)]
  117. public static int TestWriteInt(ref int data)
  118. {
  119. var result = data;
  120. Volatile.Write(ref data, 5);
  121. return result + data;
  122. }
  123. [TestCompiler(42u)]
  124. public static uint TestWriteUInt(ref uint data)
  125. {
  126. var result = data;
  127. Volatile.Write(ref data, 6);
  128. return result + data;
  129. }
  130. [TestCompiler((long)42)]
  131. public static long TestWriteLong(ref long data)
  132. {
  133. var result = data;
  134. Volatile.Write(ref data, 7);
  135. return result + data;
  136. }
  137. [TestCompiler((ulong)42)]
  138. public static ulong TestWriteULong(ref ulong data)
  139. {
  140. var result = data;
  141. Volatile.Write(ref data, 8);
  142. return result + data;
  143. }
  144. [TestCompiler(42.0f)]
  145. public static float TestWriteFloat(ref float data)
  146. {
  147. var result = data;
  148. Volatile.Write(ref data, 9);
  149. return result + data;
  150. }
  151. [TestCompiler(42.0)]
  152. public static double TestWriteDouble(ref double data)
  153. {
  154. var result = data;
  155. Volatile.Write(ref data, 10);
  156. return result + data;
  157. }
  158. [TestCompiler(typeof(UIntPtrProvider))]
  159. public static UIntPtr TestWriteUIntPtr(ref UIntPtr data)
  160. {
  161. var result = data;
  162. Volatile.Write(ref data, new UIntPtr(11));
  163. return result;
  164. }
  165. }
  166. }