ThreadedHelpers.cs
1 using System; 2 using System.Threading; 3 4 namespace Ryujinx.Graphics.GAL.Multithreading 5 { 6 static class ThreadedHelpers 7 { 8 public static void SpinUntilNonNull<T>(ref T obj) where T : class 9 { 10 Span<SpinWait> spinWait = stackalloc SpinWait[1]; 11 12 while (obj == null) 13 { 14 spinWait[0].SpinOnce(-1); 15 } 16 } 17 18 public static void SpinUntilExchange(ref int target, int value, int comparand) 19 { 20 Span<SpinWait> spinWait = stackalloc SpinWait[1]; 21 22 while (Interlocked.CompareExchange(ref target, value, comparand) != comparand) 23 { 24 spinWait[0].SpinOnce(-1); 25 } 26 } 27 } 28 }