diff options
Diffstat (limited to 'src/Ryujinx.Graphics.GAL/Multithreading/ThreadedHelpers.cs')
-rw-r--r-- | src/Ryujinx.Graphics.GAL/Multithreading/ThreadedHelpers.cs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedHelpers.cs b/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedHelpers.cs new file mode 100644 index 00000000..7ddb19e6 --- /dev/null +++ b/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedHelpers.cs @@ -0,0 +1,28 @@ +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); + } + } + } +} |