[*] Updated AuTheading::WaitFor prototype

[+/*] Missing YieldPoll MS prototype in public header
This commit is contained in:
Reece Wilson 2024-05-27 15:00:10 +01:00
parent 30b0fce882
commit a5a9fa3887
2 changed files with 20 additions and 9 deletions

View File

@ -11,7 +11,8 @@ namespace Aurora::Threading
{
using PollCallback_cb = AuFunction<bool()>;
AUKN_SYM bool YieldPollNs(bool bPermitMultipleContextSwitches, AuUInt64 qwAbsTimeoutNs, PollCallback_cb cb);
AUKN_SYM bool YieldPollNs(bool bPermitMultipleContextSwitches, AuUInt64 qwAbsTimeoutNs, const PollCallback_cb &cb);
AUKN_SYM bool YieldPoll(bool bPermitMultipleContextSwitches, AuUInt64 qwTimeoutMs, const PollCallback_cb &cb);
AUKN_SYM bool WaitForAbsNS(IWaitable *pWaitable, AuUInt64 qwAbsTimeout = 0);
AUKN_SYM bool TryWait(IWaitable *pWaitable);
@ -25,10 +26,12 @@ namespace Aurora::Threading
* See: Mutex, CriticalSection, Semaphore, Event, Thread, Async, and others
* On timeout, returns false
* On error, waitables are restored to their state at the point of WaitFors
* @warning: With kWaitForFlagTimeoutIsOr, we may have to long-poll with bad scheduling characteristics. Defer to AuAsync for thread local multiple wait scheduling, and AuIO for multiple io wait.
* Are you looking for AuIO::Loop::WaitMultipleLoopSources?
*/
AUKN_SYM bool WaitFor(const AuList<IWaitable *> &waitables, AuUInt32 uFlags, AuUInt64 uTimeout = 0);
AUKN_SYM bool WaitFor(const AuList<IWaitable *> &waitables, AuUInt32 uFlags, AuUInt64 uTimeout = 0, AuUInt32 *pIndexAwoken = nullptr);
static inline bool WaitForShared(const AuList<AuSPtr<IWaitable>> &pWaitables, AuUInt32 uFlags, AuUInt64 uTimeout)
static inline bool WaitForShared(const AuList<AuSPtr<IWaitable>> &pWaitables, AuUInt32 uFlags, AuUInt64 uTimeout = 0, AuUInt32 *pIndexAwoken = nullptr)
{
AU_DEBUG_MEMCRUNCH;
AuList<IWaitable *> waitables;
@ -39,14 +42,14 @@ namespace Aurora::Threading
waitables.push_back(pIWaitable.get());
}
return WaitFor(waitables, uFlags, uTimeout);
return WaitFor(waitables, uFlags, uTimeout, pIndexAwoken);
}
/// legacy api (~3 years old, relative to 2023)
/// @deprecated
static inline bool WaitFor(const AuList<IWaitable *> &waitables, AuUInt64 uTimeout)
{
return WaitFor(waitables, 0, uTimeout);
return WaitFor(waitables, 0, uTimeout, nullptr);
}
/// legacy api (~3 years old, relative to 2023)

View File

@ -51,7 +51,7 @@ namespace Aurora::Threading
#endif
}
AUKN_SYM bool YieldPollNs(bool bPermitMultipleContextSwitches, AuUInt64 qwAbsTimeoutNs, PollCallback_cb cb)
AUKN_SYM bool YieldPollNs(bool bPermitMultipleContextSwitches, AuUInt64 qwAbsTimeoutNs, const PollCallback_cb &cb)
{
while (!Primitives::DoTryIf(cb))
{
@ -69,15 +69,17 @@ namespace Aurora::Threading
return true;
}
AUKN_SYM bool YieldPoll(bool permitMultipleContextSwitches, AuUInt64 qwTimeoutMs, PollCallback_cb cb)
AUKN_SYM bool YieldPoll(bool bPermitMultipleContextSwitches, AuUInt64 qwTimeoutMs, const PollCallback_cb &cb)
{
return YieldPollNs(permitMultipleContextSwitches,
return YieldPollNs(bPermitMultipleContextSwitches,
qwTimeoutMs ? Time::SteadyClockNS() + AuMSToNS<AuUInt64>(qwTimeoutMs) : 0,
cb);
}
AUKN_SYM bool WaitForAbsNS(IWaitable *pWaitable, AuUInt64 qwAbsTimeout)
{
SysCheckArgNotNull(pWaitable, false);
if (pWaitable->HasLockImplementation())
{
return pWaitable->LockAbsNS(qwAbsTimeout);
@ -91,6 +93,8 @@ namespace Aurora::Threading
AUKN_SYM bool TryWait(IWaitable *pWaitable)
{
SysCheckArgNotNull(pWaitable, false);
if (pWaitable->HasLockImplementation())
{
return pWaitable->TryLock();
@ -102,7 +106,7 @@ namespace Aurora::Threading
});
}
AUKN_SYM bool WaitFor(const AuList<IWaitable *> &waitables, AuUInt32 uFlags, AuUInt64 uTimeout)
AUKN_SYM bool WaitFor(const AuList<IWaitable *> &waitables, AuUInt32 uFlags, AuUInt64 uTimeout, AuUInt32 *pIndexAwoken)
{
AU_DEBUG_MEMCRUNCH;
@ -146,6 +150,10 @@ namespace Aurora::Threading
else
{
bLocked = waitables[i]->TryLock();
if (pIndexAwoken)
{
*pIndexAwoken = i;
}
}
if (bLocked)