Fix ConcurrentSystemLocker to have exclusive lock as an option
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user