[*] Refactor ConditionEx -> IFlexibleConditionVariable

This commit is contained in:
Reece Wilson 2024-08-08 20:21:03 +01:00
parent adfca81335
commit 23a80b8039
2 changed files with 15 additions and 14 deletions

View File

@ -19,20 +19,20 @@ namespace Aurora::Threading::Primitives
Note: Missing 'pWaitable's cannnot serve as an `atomic wait for while is [not] value` operation. Note: Missing 'pWaitable's cannnot serve as an `atomic wait for while is [not] value` operation.
There are no legal use cases for this feature. It's just there. There are no legal use cases for this feature. It's just there.
*/ */
struct ConditionEx struct IFlexibleConditionVariable
{ {
virtual void WaitForSignal() = 0; virtual void WaitForSignal() = 0;
virtual void WaitForSignal(const AuSPtr<IWaitable> &pWaitable) = 0; virtual void WaitForSignal(IWaitable *pWaitable) = 0;
virtual bool WaitForSignalNS(AuUInt64 uRelativeNanoseconds) = 0; virtual bool WaitForSignalNS(AuUInt64 uRelativeNanoseconds) = 0;
virtual bool WaitForSignalNS(const AuSPtr<IWaitable> &pWaitable, AuUInt64 uRelativeNanoseconds) = 0; virtual bool WaitForSignalNS(IWaitable *pWaitable, AuUInt64 uRelativeNanoseconds) = 0;
virtual bool WaitForSignalAbsNS(AuUInt64 uAbsNanoseconds) = 0; virtual bool WaitForSignalAbsNS(AuUInt64 uAbsNanoseconds) = 0;
virtual bool WaitForSignalAbsNS(const AuSPtr<IWaitable> &pWaitable, AuUInt64 uAbsNanoseconds) = 0; virtual bool WaitForSignalAbsNS(IWaitable *pWaitable, AuUInt64 uAbsNanoseconds) = 0;
virtual void Broadcast() = 0; virtual void Broadcast() = 0;
virtual void Signal() = 0; virtual void Signal() = 0;
}; };
AUKN_SHARED_SOO_NCM(FlexibleConditionVariable, ConditionEx, kPrimitiveSizeSemaphoreCV); AUKN_SHARED_SOO_NCM(FlexibleConditionVariable, IFlexibleConditionVariable, kPrimitiveSizeSemaphoreCV);
} }

View File

@ -12,18 +12,19 @@
namespace Aurora::Threading::Primitives namespace Aurora::Threading::Primitives
{ {
struct SemaphoreConditionVariableImpl : ConditionEx struct SemaphoreConditionVariableImpl :
IFlexibleConditionVariable
{ {
SemaphoreConditionVariableImpl(); SemaphoreConditionVariableImpl();
void WaitForSignal(const AuSPtr<IWaitable> &pWaitable) override; void WaitForSignal(IWaitable *pWaitable) override;
void WaitForSignal() override; void WaitForSignal() override;
bool WaitForSignalNS(AuUInt64 uRelativeNanoseconds) override; bool WaitForSignalNS(AuUInt64 uRelativeNanoseconds) override;
bool WaitForSignalNS(const AuSPtr<IWaitable> &waitable, AuUInt64 uRelativeNanoseconds) override; bool WaitForSignalNS(IWaitable *pWaitable, AuUInt64 uRelativeNanoseconds) override;
bool WaitForSignalAbsNS(AuUInt64 uAbsNanoseconds) override; bool WaitForSignalAbsNS(AuUInt64 uAbsNanoseconds) override;
bool WaitForSignalAbsNS(const AuSPtr<IWaitable> &pWaitable, AuUInt64 uAbsNanoseconds) override; bool WaitForSignalAbsNS(IWaitable *pWaitable, AuUInt64 uAbsNanoseconds) override;
void Signal() override; void Signal() override;
void Broadcast() override; void Broadcast() override;
@ -45,7 +46,7 @@ namespace Aurora::Threading::Primitives
return WaitForSignalNS(nullptr, uRelativeNanoseconds); return WaitForSignalNS(nullptr, uRelativeNanoseconds);
} }
bool SemaphoreConditionVariableImpl::WaitForSignalAbsNS(const AuSPtr<IWaitable> &pWaitable, bool SemaphoreConditionVariableImpl::WaitForSignalAbsNS(IWaitable *pWaitable,
AuUInt64 uNanoseconds) AuUInt64 uNanoseconds)
{ {
AuAtomicAdd(&this->uWaiters_, 1u); AuAtomicAdd(&this->uWaiters_, 1u);
@ -81,14 +82,14 @@ namespace Aurora::Threading::Primitives
return bSuccess; return bSuccess;
} }
bool SemaphoreConditionVariableImpl::WaitForSignalNS(const AuSPtr<IWaitable> &pWaitable, bool SemaphoreConditionVariableImpl::WaitForSignalNS(IWaitable *pWaitable,
AuUInt64 uAbsNanoseconds) AuUInt64 uAbsNanoseconds)
{ {
return this->WaitForSignalAbsNS(pWaitable, return this->WaitForSignalAbsNS(pWaitable,
uAbsNanoseconds ? AuTime::SteadyClockNS() + uAbsNanoseconds : 0); uAbsNanoseconds ? AuTime::SteadyClockNS() + uAbsNanoseconds : 0);
} }
void SemaphoreConditionVariableImpl::WaitForSignal(const AuSPtr<IWaitable> &pWaitable) void SemaphoreConditionVariableImpl::WaitForSignal(IWaitable *pWaitable)
{ {
AuAtomicAdd(&this->uWaiters_, 1u); AuAtomicAdd(&this->uWaiters_, 1u);
@ -163,12 +164,12 @@ namespace Aurora::Threading::Primitives
} }
} }
AUKN_SYM ConditionEx *FlexibleConditionVariableNew() AUKN_SYM IFlexibleConditionVariable *FlexibleConditionVariableNew()
{ {
return _new SemaphoreConditionVariableImpl(); return _new SemaphoreConditionVariableImpl();
} }
AUKN_SYM void FlexibleConditionVariableRelease(ConditionEx *pCVEx) AUKN_SYM void FlexibleConditionVariableRelease(IFlexibleConditionVariable *pCVEx)
{ {
AuSafeDelete<SemaphoreConditionVariableImpl *>(pCVEx); AuSafeDelete<SemaphoreConditionVariableImpl *>(pCVEx);
} }