From a1974ddf4571cc922f0e25d28aabc74077396d66 Mon Sep 17 00:00:00 2001 From: q66 Date: Fri, 24 Mar 2017 15:24:07 +0100 Subject: [PATCH] clean up the helper funcs --- ostd/concurrency.hh | 46 +++++++++++---------------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/ostd/concurrency.hh b/ostd/concurrency.hh index 7c64046..77207fd 100644 --- a/ostd/concurrency.hh +++ b/ostd/concurrency.hh @@ -547,23 +547,8 @@ using coroutine_scheduler = using protected_coroutine_scheduler = basic_coroutine_scheduler; -namespace detail { - template - std::true_type has_spawn_test(decltype( - std::declval().spawn(std::declval>()) - ) *); - - template - std::false_type has_spawn_test(...); - - template - constexpr bool has_sched_spawn = decltype(has_spawn_test(0))::value; -} - -template -inline auto spawn(S &sched, F &&func, A &&...args) -> std::enable_if_t< - std::is_base_of_v -> { +template +inline void spawn(scheduler &sched, F &&func, A &&...args) { if constexpr(sizeof...(A) == 0) { sched.spawn(std::forward(func)); } else { @@ -572,20 +557,14 @@ inline auto spawn(S &sched, F &&func, A &&...args) -> std::enable_if_t< } template -inline auto spawn(F &&func, A &&...args) -> std::enable_if_t< - !std::is_base_of_v -> { - if constexpr(sizeof...(A) == 0) { - detail::current_scheduler->spawn(std::forward(func)); - } else { - detail::current_scheduler->spawn( - std::bind(std::forward(func), std::forward(args)...) - ); - } +inline void spawn(F &&func, A &&...args) { + spawn( + *detail::current_scheduler, + std::forward(func), std::forward(args)... + ); } -template -inline void yield(S &sched) { +inline void yield(scheduler &sched) { sched.yield(); } @@ -593,8 +572,8 @@ inline void yield() { detail::current_scheduler->yield(); } -template -inline channel make_channel(S &sched) { +template +inline channel make_channel(scheduler &sched) { return channel{[&sched]() { return sched.make_condition(); }}; @@ -602,10 +581,7 @@ inline channel make_channel(S &sched) { template inline channel make_channel() { - auto *curr = detail::current_scheduler; - return channel{[curr]() { - return curr->make_condition(); - }}; + return make_channel(*detail::current_scheduler); } } /* namespace ostd */