ThreadedHelpers.cs 728 B

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