From 6ec2fcc4b6d456454f5f2e304f55e29b50cea65d Mon Sep 17 00:00:00 2001 From: J Reece Wilson Date: Sat, 12 Aug 2023 11:18:19 +0100 Subject: [PATCH] [*] Added timeout awareness in ConditionEx; returns false on timeout [*] Updated Linux SOO sizes --- .../Threading/Primitives/ConditionEx.hpp | 6 +++--- .../Threading/Primitives/SOOPrimitives.hpp | 20 +++++++++---------- Source/Threading/Primitives/AuConditionEx.cpp | 16 ++++++++------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Include/Aurora/Threading/Primitives/ConditionEx.hpp b/Include/Aurora/Threading/Primitives/ConditionEx.hpp index e51c594f..21eb46c3 100644 --- a/Include/Aurora/Threading/Primitives/ConditionEx.hpp +++ b/Include/Aurora/Threading/Primitives/ConditionEx.hpp @@ -21,9 +21,9 @@ namespace Aurora::Threading::Primitives virtual void WaitForSignal(IWaitable *pWaitable) = 0; virtual void WaitForSignal(const AuSPtr &pWaitable) = 0; - virtual void WaitForSignalNS(AuUInt64 uRelativeNanoseconds) = 0; - virtual void WaitForSignalNS(IWaitable *pWaitable, AuUInt64 uRelativeNanoseconds) = 0; - virtual void WaitForSignalNS(const AuSPtr &pWaitable, AuUInt64 uRelativeNanoseconds) = 0; + virtual bool WaitForSignalNS(AuUInt64 uRelativeNanoseconds) = 0; + virtual bool WaitForSignalNS(IWaitable *pWaitable, AuUInt64 uRelativeNanoseconds) = 0; + virtual bool WaitForSignalNS(const AuSPtr &pWaitable, AuUInt64 uRelativeNanoseconds) = 0; virtual void Broadcast() = 0; virtual void Signal() = 0; diff --git a/Include/Aurora/Threading/Primitives/SOOPrimitives.hpp b/Include/Aurora/Threading/Primitives/SOOPrimitives.hpp index 68493cf3..368af0aa 100644 --- a/Include/Aurora/Threading/Primitives/SOOPrimitives.hpp +++ b/Include/Aurora/Threading/Primitives/SOOPrimitives.hpp @@ -37,19 +37,19 @@ namespace Aurora::Threading::Primitives static const auto kPrimitiveSize64LinuxMutex = 16; static const auto kPrimitiveSize64LinuxSemaphore = 16; - static const auto kPrimitiveSize64LinuxCS = 128; - static const auto kPrimitiveSize64LinuxEvent = 152; - static const auto kPrimitiveSize64LinuxRWLock = 200; - static const auto kPrimitiveSize64LinuxCond = 88; - static const auto kPrimitiveSize64LinuxCondMutex = 48; + static const auto kPrimitiveSize64LinuxCS = 40; + static const auto kPrimitiveSize64LinuxEvent = 80; + static const auto kPrimitiveSize64LinuxRWLock = 88; + static const auto kPrimitiveSize64LinuxCond = 48; + static const auto kPrimitiveSize64LinuxCondMutex = 16; static const auto kPrimitiveSize32LinuxMutex = 8; static const auto kPrimitiveSize32LinuxSemaphore = 8; - static const auto kPrimitiveSize32LinuxCS = 128; - static const auto kPrimitiveSize32LinuxEvent = 152; - static const auto kPrimitiveSize32LinuxRWLock = 200; - static const auto kPrimitiveSize32LinuxCond = 88; - static const auto kPrimitiveSize32LinuxCondMutex = 48; + static const auto kPrimitiveSize32LinuxCS = 40; + static const auto kPrimitiveSize32LinuxEvent = 80; + static const auto kPrimitiveSize32LinuxRWLock = 88; + static const auto kPrimitiveSize32LinuxCond = 48; + static const auto kPrimitiveSize32LinuxCondMutex = 16; // TODO: Other platforms... diff --git a/Source/Threading/Primitives/AuConditionEx.cpp b/Source/Threading/Primitives/AuConditionEx.cpp index 017b2cb9..e56cd7b5 100644 --- a/Source/Threading/Primitives/AuConditionEx.cpp +++ b/Source/Threading/Primitives/AuConditionEx.cpp @@ -19,9 +19,9 @@ namespace Aurora::Threading::Primitives void WaitForSignal(const AuSPtr &pWaitable) override; void WaitForSignal() override; - void WaitForSignalNS(AuUInt64 uRelativeNanoseconds) override; - void WaitForSignalNS(IWaitable *waitable, AuUInt64 uRelativeNanoseconds) override; - void WaitForSignalNS(const AuSPtr &waitable, AuUInt64 uRelativeNanoseconds) override; + bool WaitForSignalNS(AuUInt64 uRelativeNanoseconds) override; + bool WaitForSignalNS(IWaitable *waitable, AuUInt64 uRelativeNanoseconds) override; + bool WaitForSignalNS(const AuSPtr &waitable, AuUInt64 uRelativeNanoseconds) override; void Signal() override; void Broadcast() override; @@ -38,18 +38,18 @@ namespace Aurora::Threading::Primitives } - void SemaphoreConditionVariableImpl::WaitForSignalNS(AuUInt64 uRelativeNanoseconds) + bool SemaphoreConditionVariableImpl::WaitForSignalNS(AuUInt64 uRelativeNanoseconds) { - WaitForSignalNS(nullptr, uRelativeNanoseconds); + return WaitForSignalNS(nullptr, uRelativeNanoseconds); } - void SemaphoreConditionVariableImpl::WaitForSignalNS(IWaitable *pWaitable, AuUInt64 uRelativeNanoseconds) + bool SemaphoreConditionVariableImpl::WaitForSignalNS(IWaitable *pWaitable, AuUInt64 uRelativeNanoseconds) { return WaitForSignalNS(pWaitable ? AuUnsafeRaiiToShared(pWaitable) : AuSPtr {}, uRelativeNanoseconds); } - void SemaphoreConditionVariableImpl::WaitForSignalNS(const AuSPtr &pWaitable, + bool SemaphoreConditionVariableImpl::WaitForSignalNS(const AuSPtr &pWaitable, AuUInt64 uRelativeNanoseconds) { AuAtomicAdd(&this->uWaiters_, 1u); @@ -80,6 +80,8 @@ namespace Aurora::Threading::Primitives { pWaitable->Lock(); } + + return bSuccess; } void SemaphoreConditionVariableImpl::WaitForSignal(IWaitable *pWaitable)