From 45e82d21f4e15234ce8b7cf39d005fa929f535c8 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 26 Jun 2025 19:51:06 +0200 Subject: [PATCH] Fix `ConcurrentSystemLocker` to guard for a single writer at once --- Source/Engine/Threading/ConcurrentSystemLocker.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/Engine/Threading/ConcurrentSystemLocker.cpp b/Source/Engine/Threading/ConcurrentSystemLocker.cpp index f8eab96d9..c8debb561 100644 --- a/Source/Engine/Threading/ConcurrentSystemLocker.cpp +++ b/Source/Engine/Threading/ConcurrentSystemLocker.cpp @@ -22,6 +22,14 @@ RETRY: goto RETRY; } + // Writers have to check themselves to (one write at the same time - just like a mutex) + if (write && Platform::AtomicRead(thisCounter) != 0) + { + // Someone else is doing opposite operation so wait for it's end + Platform::Sleep(0); + goto RETRY; + } + // Mark that we entered this section Platform::InterlockedIncrement(thisCounter);