0
0
Fork 0
mirror of https://github.com/GreemDev/Ryujinx.git synced 2025-01-25 07:02:00 +00:00
Ryujinx/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedHelpers.cs
TSRBerry 2989c163a8
editorconfig: Set default encoding to UTF-8 (#5793)
* editorconfig: Add default charset

* Change file encoding from UTF-8-BOM to UTF-8
2023-12-04 14:17:13 +01:00

28 lines
725 B
C#

using System;
using System.Threading;
namespace Ryujinx.Graphics.GAL.Multithreading
{
static class ThreadedHelpers
{
public static void SpinUntilNonNull<T>(ref T obj) where T : class
{
Span<SpinWait> spinWait = stackalloc SpinWait[1];
while (obj == null)
{
spinWait[0].SpinOnce(-1);
}
}
public static void SpinUntilExchange(ref int target, int value, int comparand)
{
Span<SpinWait> spinWait = stackalloc SpinWait[1];
while (Interlocked.CompareExchange(ref target, value, comparand) != comparand)
{
spinWait[0].SpinOnce(-1);
}
}
}
}