From f847ab049a8e67b7c5dfff6ebd6f8e07657200b4 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Mon, 21 Aug 2023 16:25:16 +0100 Subject: [PATCH] [+] ThreadingConfig::bPreferRWLockReadLockSpin --- Include/Aurora/Runtime.hpp | 1 + Source/Threading/Primitives/AuRWLock.cpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Include/Aurora/Runtime.hpp b/Include/Aurora/Runtime.hpp index 28a8f165..3179582d 100644 --- a/Include/Aurora/Runtime.hpp +++ b/Include/Aurora/Runtime.hpp @@ -361,6 +361,7 @@ namespace Aurora AuUInt64 bPreferLinuxMutexSpinTryLock : 1 { true }; AuUInt64 bPreferLinuxCondMutexSpinTryLock : 1 { true }; AuUInt64 bPreferEmulatedWakeOnAddress : 1 { false }; + AuUInt64 bPreferRWLockReadLockSpin : 1 { true }; }; struct DummyConfig diff --git a/Source/Threading/Primitives/AuRWLock.cpp b/Source/Threading/Primitives/AuRWLock.cpp index 8ab17a99..1ad2a2ad 100644 --- a/Source/Threading/Primitives/AuRWLock.cpp +++ b/Source/Threading/Primitives/AuRWLock.cpp @@ -141,7 +141,7 @@ namespace Aurora::Threading::Primitives template bool RWLockImpl::LockReadNSAbs(AuUInt64 uTimeout) { - if (this->TryLockReadNoSpin()) + if (this->TryLockRead()) { return true; } @@ -197,6 +197,11 @@ namespace Aurora::Threading::Primitives AuInt64 uEndTime = uTimeout ? AuTime::SteadyClockNS() + uTimeout : 0; + if (this->TryLockRead()) + { + return true; + } + AuInt32 iCurState {}; do { @@ -421,10 +426,17 @@ namespace Aurora::Threading::Primitives template bool RWLockImpl::TryLockRead() { - return DoTryIf([=]() + if (gRuntimeConfig.threadingConfig.bPreferRWLockReadLockSpin) + { + return DoTryIf([=]() + { + return TryLockReadNoSpin(); + }); + } + else { return TryLockReadNoSpin(); - }); + } } template