From 423dbc88883d46d11293156e3320b08ba7a90797 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Sat, 21 Jan 2023 19:49:55 +0000 Subject: [PATCH] Use volatile read/writes for GAL threading (#4327) --- Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs b/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs index 58058be2c..74326f1d2 100644 --- a/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs +++ b/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs @@ -135,7 +135,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading // The other thread can only increase the command count. // We can assume that if it is above 0, it will stay there or get higher. - while (_commandCount > 0 && Volatile.Read(ref _interruptAction) == null) + while (Volatile.Read(ref _commandCount) > 0 && Volatile.Read(ref _interruptAction) == null) { int commandPtr = _consumerPtr; @@ -169,7 +169,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading internal ref T New() where T : struct { - while (_producerPtr == (_consumerPtr + QueueCount - 1) % QueueCount) + while (_producerPtr == (Volatile.Read(ref _consumerPtr) + QueueCount - 1) % QueueCount) { // If incrementing the producer pointer would overflow, we need to wait. // _consumerPtr can only move forward, so there's no race to worry about here.