From 0f62b03da0295a407b406dcda92bc6f499046d3a Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Wed, 20 Sep 2023 17:30:38 +0100 Subject: [PATCH] [+] AuFutexBarrier::EnterTimedEx --- .../Threading/Waitables/FutexBarrier.hpp | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/Include/Aurora/Threading/Waitables/FutexBarrier.hpp b/Include/Aurora/Threading/Waitables/FutexBarrier.hpp index 9b097510..3cad3980 100644 --- a/Include/Aurora/Threading/Waitables/FutexBarrier.hpp +++ b/Include/Aurora/Threading/Waitables/FutexBarrier.hpp @@ -35,6 +35,18 @@ namespace Aurora::Threading::Waitables return AuMakePair(bSuccess, bTimeout); } + inline AuPair + EnterTimedEx(AuUInt64 uTimeoutAbsNS, + AuVoidFunc callOnce) + { + bool bTimeout {}, bSuccess {}; + bSuccess = this->Park(bTimeout, + true, + uTimeoutAbsNS, + callOnce); + return AuMakePair(bSuccess, bTimeout); + } + inline bool TryEnter() { return this->TryEnterNoSpin(); @@ -53,7 +65,11 @@ namespace Aurora::Threading::Waitables } private: - auline bool Park(bool &bTimedOut, bool bTakeOwnership, AuUInt64 uTimeoutAbsNS) + + auline bool Park(bool &bTimedOut, + bool bTakeOwnership, + AuUInt64 uTimeoutAbsNS, + AuVoidFunc callOnce = {}) { static const AuUInt32 kRef { 0 }; @@ -61,7 +77,7 @@ namespace Aurora::Threading::Waitables if (bTakeOwnership) { - if (!this->TryEnterNoSpin()) + if (!this->TryEnterNoSpin(callOnce)) { return false; } @@ -93,7 +109,7 @@ namespace Aurora::Threading::Waitables return true; } - auline bool TryEnterNoSpin() + auline bool TryEnterNoSpin(AuVoidFunc callOnce = {}) { AuUInt32 uState; @@ -103,6 +119,11 @@ namespace Aurora::Threading::Waitables { if (uState == 1) { + if (callOnce) + { + callOnce(); + } + AuAtomicStore(&this->uAtomicState, 1u); WakeAllOnAddress((const void *)&this->uAtomicState); }