AuroraRuntime/Include/Aurora/Threading/WaitFor.hpp
2021-06-27 22:25:29 +01:00

36 lines
1.3 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: WaitFor.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::Threading
{
using PollCallback_cb = std::function<bool()>;
AUKN_SYM bool YieldPollNs(bool permitMultipleContextSwitches, AuUInt64 timeoutNs, PollCallback_cb cb);
AUKN_SYM bool YieldPoll(bool permitMultipleContextSwitches, AuUInt64 timeoutMs, PollCallback_cb cb);
/*!
Waits for a list of IWaitable objects. <br>
See: Mutex, CriticalSection, Semaphore, Event, Thread, Async, and others
*/
AUKN_SYM bool WaitFor(IWaitable *waitable, AuUInt64 timeout = 0);
static bool WaitFor(std::atomic<bool> &value, AuUInt64 timeout = 0)
{
Waitables::BooleanWaitable waitable(value);
return WaitFor(&waitable, timeout);
}
/*!
Waits on a list of IWaitable objects. <br>
See: Mutex, CriticalSection, Semaphore, Event, Thread, Async, and others <br>
On timeout, returns false <br>
On error, waitables are restored to their state at the point of WaitFors call
*/
AUKN_SYM bool WaitFor(const AuList<IWaitable *> &waitables, AuUInt64 timeout = 0);
}