[*] Expose AsyncApp::Poll
This commit is contained in:
parent
a1df310ddc
commit
1f8d06cbf0
@ -51,27 +51,27 @@ namespace Aurora::Async
|
||||
};
|
||||
|
||||
|
||||
template<typename Info_t = AVoid, typename Result_t = AVoid>
|
||||
template<class Info_t = AVoid, class Result_t = AVoid>
|
||||
struct FJob
|
||||
{
|
||||
std::function<void(const Info_t &, const Result_t &)> onSuccess = 0;
|
||||
std::function<void(const Info_t &, bool)> onFailure = 0;
|
||||
};
|
||||
|
||||
template<typename Info_t = AVoid, typename Result_t = AVoid>
|
||||
template<class Info_t = AVoid, class Result_t = AVoid>
|
||||
struct CJob
|
||||
{
|
||||
void(* onSuccess)(const Info_t &, const Result_t &); //
|
||||
void(* onFailure)(const Info_t &, bool taskNeverDispatched); // called from caller thread if taskNeverDispatched
|
||||
};
|
||||
|
||||
template<typename Info_t = AVoid, typename Result_t = AVoid>
|
||||
template<class Info_t = AVoid, class Result_t = AVoid>
|
||||
struct FTask
|
||||
{
|
||||
std::function<std::optional<Result_t>(const Info_t &)> onFrame = 0;
|
||||
};
|
||||
|
||||
template<typename Info_t = AVoid, typename Result_t = AVoid>
|
||||
template<class Info_t = AVoid, class Result_t = AVoid>
|
||||
struct CTask
|
||||
{
|
||||
std::optional<Result_t>(* onFrame)(const Info_t &);
|
||||
@ -286,9 +286,39 @@ namespace Aurora::Async
|
||||
};
|
||||
|
||||
template<typename B, typename... Args>
|
||||
static void TranslateAsyncFunctionToDispatcher()
|
||||
static std::function<void(Args...)> TranslateAsyncFunctionToDispatcher(std::function<void(Args...)> func)
|
||||
{
|
||||
auto cur = GetAsyncApp()->GetCurrentThread();
|
||||
return [=](Args... in) -> void
|
||||
{
|
||||
auto work = std::make_shared<BasicWorkStdFunc>([=]() -> void {
|
||||
func(in...);
|
||||
});
|
||||
auto workItem = NewWorkItem(cur, work);
|
||||
if (!workItem) throw "can't dispatch async call; out of memory";
|
||||
workItem->Dispatch();
|
||||
};
|
||||
}
|
||||
|
||||
template<typename B, typename... Args>
|
||||
static std::function<void(std::function<void(const B&)>, Args...)> TranslateAsyncReturnableFunctionToDispatcher(std::function<B(Args...)> func)
|
||||
{
|
||||
auto cur = GetAsyncApp()->GetCurrentThread();
|
||||
return [=](std::function<void(const B&)> callback, Args... in) -> void
|
||||
{
|
||||
auto work = std::make_shared<BasicWorkCallback<AVoid, B>>();
|
||||
work.task.onProcess = [](const AVoid &) -> std::optional<B>
|
||||
{
|
||||
return func(in...);
|
||||
};
|
||||
work.callback.onSuccess = [=](const AVoid &, const B &ret)
|
||||
{
|
||||
callback(ret);
|
||||
};
|
||||
auto workItem = NewWorkItem(cur, work);
|
||||
if (!workItem) throw "can't dispatch async call; out of memory";
|
||||
workItem->Dispatch();
|
||||
};
|
||||
}
|
||||
|
||||
class IAsyncApp
|
||||
@ -322,5 +352,7 @@ namespace Aurora::Async
|
||||
// Debug
|
||||
virtual void AssertInThreadGroup(ThreadGroup_t thread) = 0;
|
||||
virtual void AssertWorker(WorkerId_t id) = 0;
|
||||
|
||||
virtual bool Poll(bool block) = 0;
|
||||
};
|
||||
}
|
@ -55,11 +55,11 @@ namespace Aurora::Async
|
||||
|
||||
void ShutdownOutOfTasks();
|
||||
|
||||
bool Poll(bool block) override;
|
||||
private:
|
||||
|
||||
// TODO: BarrierMultiple
|
||||
bool Barrier(WorkerId_t, AuUInt32 ms, bool requireSignal, bool drop);
|
||||
bool Poll(bool a);
|
||||
|
||||
Threading::Primitives::RWLockUnique_t rwlock_;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user