/*** Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: WaitSingle.Generic.cpp Date: 2021-10-2 Author: Reece ***/ #include #include "WaitSingleBase.hpp" namespace Aurora::IO::Loop { bool WaitSingleBase::IsSignaled() { bool val {}; AuUInt one {AuNumericLimits::max()}; AuUInt two {AuNumericLimits::max()}; this->OnPresleep(); if (this->Singular()) { #if defined(AURORA_IS_POSIX_DERIVED) auto handle = this->GetHandle(); auto handleRw = this->GetWriteHandle(); val = this->WaitForOne(0, handle, handleRw); #else auto handle = this->GetHandle(); val = this->WaitForOne(0, handle); #endif if (val) { val = this->OnTrigger(handle); } } else { #if defined(AURORA_IS_POSIX_DERIVED) auto handles = this->GetHandles(); auto handlesRw = this->GetWriteHandles(); val = this->WaitForAtleastOne(0, handles, handlesRw, one, two); if (one == -1) one = two; #else auto handles = this->GetHandles(); val = this->WaitForAtleastOne(0, handles, one); #endif if (val) { val = this->OnTrigger(one); } } this->OnFinishSleep(); return val; } bool WaitSingleBase::WaitOn(AuUInt32 timeout) { bool val {}; AuUInt one {AuNumericLimits::max()}; AuUInt two {AuNumericLimits::max()}; this->OnPresleep(); if (this->Singular()) { #if defined(AURORA_IS_POSIX_DERIVED) auto handle = this->GetHandle(); auto handleRw = this->GetWriteHandle(); val = this->WaitForOne(timeout ? timeout : AuUInt32(-1), handle, handleRw); #else auto handle = this->GetHandle(); val = this->WaitForOne(timeout ? timeout : AuUInt32(-1), handle); #endif if (val) { val = this->OnTrigger(handle); } } else { #if defined(AURORA_IS_POSIX_DERIVED) auto handles = this->GetHandles(); auto handlesRw = this->GetWriteHandles(); val = this->WaitForAtleastOne(timeout ? timeout : AuUInt32(-1), handles, handlesRw, one, two); if (one == -1) one = two; #else auto handles = this->GetHandles(); val = this->WaitForAtleastOne(timeout ? timeout : AuUInt32(-1), handles, one); #endif if (val) { val = this->OnTrigger(one); } } this->OnFinishSleep(); return val; } }