Fix ConcurrentSystemLocker to have exclusive lock as an option

This commit is contained in:
Wojtek Figat
2025-06-29 19:16:41 +02:00
parent 43d11264f8
commit 78d519cb9a
4 changed files with 14 additions and 12 deletions

View File

@@ -8,7 +8,7 @@ ConcurrentSystemLocker::ConcurrentSystemLocker()
_counters[0] = _counters[1] = 0;
}
void ConcurrentSystemLocker::Begin(bool write)
void ConcurrentSystemLocker::Begin(bool write, bool exclusively)
{
volatile int64* thisCounter = &_counters[write];
volatile int64* otherCounter = &_counters[!write];
@@ -22,8 +22,8 @@ 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)
// Writers might want to check themselves for a single writer at the same time - just like a mutex
if (exclusively && Platform::AtomicRead(thisCounter) != 0)
{
// Someone else is doing opposite operation so wait for it's end
Platform::Sleep(0);

View File

@@ -17,7 +17,7 @@ public:
NON_COPYABLE(ConcurrentSystemLocker);
ConcurrentSystemLocker();
void Begin(bool write);
void Begin(bool write, bool exclusively = false);
void End(bool write);
public:
@@ -26,10 +26,10 @@ public:
{
NON_COPYABLE(Scope);
Scope(ConcurrentSystemLocker& locker)
Scope(ConcurrentSystemLocker& locker, bool exclusively = false)
: _locker(locker)
{
_locker.Begin(Write);
_locker.Begin(Write, exclusively);
}
~Scope()