From 568a51c489ba1c4b4dc5f0936733187eb96f1d5d Mon Sep 17 00:00:00 2001 From: q66 Date: Sun, 22 Apr 2018 21:14:18 +0200 Subject: [PATCH] subtask registration in make_task --- ostd/build/make.hh | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/ostd/build/make.hh b/ostd/build/make.hh index fcedd6e..fd0b71c 100644 --- a/ostd/build/make.hh +++ b/ostd/build/make.hh @@ -228,7 +228,6 @@ struct make_task { )); } ); - p_coro->resume(); } bool done() const { @@ -239,6 +238,21 @@ struct make_task { p_coro->resume(); } + void add_task(std::future f) { + for (;;) { + auto fs = f.wait_for(std::chrono::seconds(0)); + if (fs != std::future_status::ready) { + /* keep yielding until ready */ + auto &cc = static_cast &>( + *coroutine_context::current() + ); + (coroutine::yield_type(cc))(); + } else { + break; + } + } + } + private: std::unique_ptr> p_coro{}; }; @@ -255,26 +269,14 @@ struct make { } void push_task(std::function func) { - auto f = p_tpool.push([func = std::move(func), this]() { + p_current->add_task(p_tpool.push([func = std::move(func), this]() { func(); { std::lock_guard l{p_mtx}; p_avail = true; } p_cond.notify_one(); - }); - for (;;) { - auto fs = f.wait_for(std::chrono::seconds(0)); - if (fs != std::future_status::ready) { - /* keep yielding until ready */ - auto &cc = static_cast &>( - *coroutine_context::current() - ); - (coroutine::yield_type(cc))(); - } else { - break; - } - } + })); } make_rule &rule(string_range tgt) { @@ -320,6 +322,7 @@ private: try { auto t = std::move(tasks.front()); tasks.pop(); + p_current = &t; t.resume(); if (!t.done()) { /* still not dead, re-push */ @@ -332,6 +335,7 @@ private: auto t = std::move(tasks.front()); tasks.pop(); while (!t.done()) { + p_current = &t; t.resume(); } } catch (make_error const &) { @@ -393,6 +397,8 @@ private: } if (rl && (rl->action() || detail::check_exec(tname, rdeps))) { make_task t{tname, std::move(rdeps), *rl}; + p_current = &t; + t.resume(); if (!t.done()) { p_waiting.top()->push(std::move(t)); } @@ -473,6 +479,7 @@ private: std::mutex p_mtx{}; std::condition_variable p_cond{}; std::stack *> p_waiting{}; + make_task *p_current = nullptr; bool p_avail = false; };