From 19eb73ff543c81c6886725a20dea0060cb0c0c26 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 2 Oct 2015 14:56:27 +0200 Subject: 7.3 --- zen/async_task.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'zen/async_task.h') diff --git a/zen/async_task.h b/zen/async_task.h index 5c6f7f6e..d8f489a3 100644 --- a/zen/async_task.h +++ b/zen/async_task.h @@ -11,7 +11,6 @@ #include #include "thread.h" #include "scope_guard.h" -//#include "type_tools.h" namespace zen { @@ -19,25 +18,25 @@ namespace zen class AsyncTasks { public: - AsyncTasks() : inRecursion(false) {} + AsyncTasks() {} template - void add(Fun doAsync, Fun2 evalOnGui) - //equivalent to "evalOnGui(doAsync())" - // -> doAsync: the usual thread-safety requirements apply! + void add(Fun runAsync, Fun2 evalOnGui) + //equivalent to "evalOnGui(runAsync())" + // -> runAsync: the usual thread-safety requirements apply! // -> evalOnGui: no thread-safety concerns, but must only reference variables with greater-equal lifetime than the AsyncTask instance! { tasks.push_back(zen::runAsync([=]() -> std::function { - auto result = doAsync(); + auto result = runAsync(); return [=]{ evalOnGui(result); }; })); } template - void add2(Fun doAsync, Fun2 evalOnGui) //for evalOnGui taking no parameters + void add2(Fun runAsync, Fun2 evalOnGui) //for evalOnGui taking no parameters { - tasks.push_back(zen::runAsync([doAsync, evalOnGui]() -> std::function { doAsync(); return [evalOnGui]{ evalOnGui(); }; })); + tasks.push_back(zen::runAsync([runAsync, evalOnGui]() -> std::function { runAsync(); return [evalOnGui]{ evalOnGui(); }; })); } void evalResults() //call from gui thread repreatedly @@ -47,9 +46,9 @@ public: inRecursion = true; ZEN_ON_SCOPE_EXIT(inRecursion = false); - tasks.remove_if([](boost::unique_future>& ft) -> bool + tasks.remove_if([](std::future>& ft) -> bool { - if (ft.is_ready()) + if (isReady(ft)) { (ft.get())(); return true; @@ -62,8 +61,11 @@ public: bool empty() const { return tasks.empty(); } private: - bool inRecursion; - std::list>> tasks; + AsyncTasks (const AsyncTasks&) = delete; + AsyncTasks& operator=(const AsyncTasks&) = delete; + + bool inRecursion = false; + std::list>> tasks; }; } -- cgit