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