[*] 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
|
struct FJob
|
||||||
{
|
{
|
||||||
std::function<void(const Info_t &, const Result_t &)> onSuccess = 0;
|
std::function<void(const Info_t &, const Result_t &)> onSuccess = 0;
|
||||||
std::function<void(const Info_t &, bool)> onFailure = 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
|
struct CJob
|
||||||
{
|
{
|
||||||
void(* onSuccess)(const Info_t &, const Result_t &); //
|
void(* onSuccess)(const Info_t &, const Result_t &); //
|
||||||
void(* onFailure)(const Info_t &, bool taskNeverDispatched); // called from caller thread if taskNeverDispatched
|
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
|
struct FTask
|
||||||
{
|
{
|
||||||
std::function<std::optional<Result_t>(const Info_t &)> onFrame = 0;
|
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
|
struct CTask
|
||||||
{
|
{
|
||||||
std::optional<Result_t>(* onFrame)(const Info_t &);
|
std::optional<Result_t>(* onFrame)(const Info_t &);
|
||||||
@ -284,11 +284,41 @@ namespace Aurora::Async
|
|||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename B, typename... Args>
|
||||||
|
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>
|
template<typename B, typename... Args>
|
||||||
static void TranslateAsyncFunctionToDispatcher()
|
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
|
class IAsyncApp
|
||||||
@ -322,5 +352,7 @@ namespace Aurora::Async
|
|||||||
// Debug
|
// Debug
|
||||||
virtual void AssertInThreadGroup(ThreadGroup_t thread) = 0;
|
virtual void AssertInThreadGroup(ThreadGroup_t thread) = 0;
|
||||||
virtual void AssertWorker(WorkerId_t id) = 0;
|
virtual void AssertWorker(WorkerId_t id) = 0;
|
||||||
|
|
||||||
|
virtual bool Poll(bool block) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -54,12 +54,12 @@ namespace Aurora::Async
|
|||||||
void Run(DispatchTarget_t target, AuSPtr<IAsyncRunnable> runnable);
|
void Run(DispatchTarget_t target, AuSPtr<IAsyncRunnable> runnable);
|
||||||
|
|
||||||
void ShutdownOutOfTasks();
|
void ShutdownOutOfTasks();
|
||||||
|
|
||||||
|
bool Poll(bool block) override;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// TODO: BarrierMultiple
|
// TODO: BarrierMultiple
|
||||||
bool Barrier(WorkerId_t, AuUInt32 ms, bool requireSignal, bool drop);
|
bool Barrier(WorkerId_t, AuUInt32 ms, bool requireSignal, bool drop);
|
||||||
bool Poll(bool a);
|
|
||||||
|
|
||||||
Threading::Primitives::RWLockUnique_t rwlock_;
|
Threading::Primitives::RWLockUnique_t rwlock_;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user