From f4835ee70e7059e5f84762a5f4d6323a5880b168 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Fri, 11 Apr 2014 18:05:55 +0200 Subject: [PATCH] re-enable await_emu --- example/cpp11/asymmetric/Jamfile.v2 | 6 +++--- example/cpp11/asymmetric/await_emu.cpp | 24 +++++++++++++----------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/example/cpp11/asymmetric/Jamfile.v2 b/example/cpp11/asymmetric/Jamfile.v2 index 335f780..f381ddc 100644 --- a/example/cpp11/asymmetric/Jamfile.v2 +++ b/example/cpp11/asymmetric/Jamfile.v2 @@ -45,6 +45,6 @@ exe iterator_range : iterator_range.cpp ; -#exe await_emu -# : await_emu.cpp -# ; +exe await_emu + : await_emu.cpp + ; diff --git a/example/cpp11/asymmetric/await_emu.cpp b/example/cpp11/asymmetric/await_emu.cpp index 5b2dbe2..4cabff2 100644 --- a/example/cpp11/asymmetric/await_emu.cpp +++ b/example/cpp11/asymmetric/await_emu.cpp @@ -15,7 +15,8 @@ #define BOOST_THREAD_PROVIDES_FUTURE #define BOOST_RESULT_OF_USE_DECLTYPE -#include +#include +#include #include #include #include @@ -40,19 +41,19 @@ template class concurrent_queue { queue q; - mutex m; - condition_variable c; + boost::mutex m; + boost::condition_variable c; public: template void push(U &&u) { - lock_guard l(m); + boost::lock_guard l(m); q.push( forward(u) ); c.notify_one(); } void pop(T &result) { - unique_lock u(m); + boost::unique_lock u(m); c.wait(u, [&]{return !q.empty();} ); result = move_if_noexcept(q.front()); q.pop(); @@ -65,13 +66,13 @@ auto finished = false; void reschedule() { - this_thread::sleep_for(chrono::milliseconds( rand() % 2000 )); + this_thread::sleep_for(boost::chrono::milliseconds( rand() % 2000 )); } // ___________________________________________________________ // -typedef coroutines::asymmetric_coroutine::pull_type coro_pull; -typedef coroutines::asymmetric_coroutine::push_type coro_push; +typedef coroutines::asymmetric_coroutine::pull_type coro_pull; +typedef coroutines::asymmetric_coroutine::push_type coro_push; struct CurrentCoro { @@ -119,9 +120,10 @@ struct Awaiter auto operator*(Future &&ft) -> decltype(ft.get()) { typedef decltype(ft.get()) Result; + typedef typename boost::remove_reference::type FutureValue; auto &¤t_coro = coro_stack.top(); - auto result = ft.then([current_coro](Future &ft) -> Result + auto result = ft.then([current_coro](FutureValue ready) -> Result { main_tasks.push([current_coro] { @@ -129,7 +131,7 @@ struct Awaiter (*coro_stack.top().coro)(); coro_stack.pop(); }); - return ft.get(); + return ready.get(); }); (*coro_stack.top().caller)(); return result.get(); @@ -188,6 +190,6 @@ void async_user_handler() for(auto i=0; i!=5; ++i) fs.push_back( asynchronous([i]{ return foo(i+1); }) ); - for(auto &&f : fs) + BOOST_FOREACH(auto &&f, fs) cout << await f << ":\tafter end" << endl; }