diff --git a/ostd/concurrency.hh b/ostd/concurrency.hh index 77207fd..292bbf0 100644 --- a/ostd/concurrency.hh +++ b/ostd/concurrency.hh @@ -30,6 +30,24 @@ struct scheduler { virtual void spawn(std::function) = 0; virtual void yield() = 0; virtual generic_condvar make_condition() = 0; + + template + void spawn(F &&func, A &&...args) { + if constexpr(sizeof...(A) == 0) { + spawn(std::function{func}); + } else { + spawn(std::function{ + std::bind(std::forward(func), std::forward(args)...) + }); + } + } + + template + channel make_channel() { + return channel{[this]() { + return make_condition(); + }}; + } }; namespace detail { @@ -547,41 +565,20 @@ using coroutine_scheduler = using protected_coroutine_scheduler = basic_coroutine_scheduler; -template -inline void spawn(scheduler &sched, F &&func, A &&...args) { - if constexpr(sizeof...(A) == 0) { - sched.spawn(std::forward(func)); - } else { - sched.spawn(std::bind(std::forward(func), std::forward(args)...)); - } -} - template inline void spawn(F &&func, A &&...args) { - spawn( - *detail::current_scheduler, + detail::current_scheduler->spawn( std::forward(func), std::forward(args)... ); } -inline void yield(scheduler &sched) { - sched.yield(); -} - inline void yield() { detail::current_scheduler->yield(); } -template -inline channel make_channel(scheduler &sched) { - return channel{[&sched]() { - return sched.make_condition(); - }}; -} - template inline channel make_channel() { - return make_channel(*detail::current_scheduler); + return detail::current_scheduler->make_channel(); } } /* namespace ostd */