diff --git a/ostd/concurrency.hh b/ostd/concurrency.hh index f1d9079..474b863 100644 --- a/ostd/concurrency.hh +++ b/ostd/concurrency.hh @@ -607,8 +607,23 @@ 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 void spawn_in(S &sched, F &&func, A &&...args) { +inline auto spawn(S &sched, F &&func, A &&...args) -> std::enable_if_t< + detail::has_sched_spawn +> { if constexpr(sizeof...(A) == 0) { sched.spawn(std::forward(func)); } else { @@ -617,7 +632,9 @@ inline void spawn_in(S &sched, F &&func, A &&...args) { } template -inline void spawn(F &&func, A &&...args) { +inline auto spawn(F &&func, A &&...args) -> std::enable_if_t< + !detail::has_sched_spawn +> { if constexpr(sizeof...(A) == 0) { detail::current_sched_iface.spawn(std::forward(func)); } else { @@ -628,7 +645,7 @@ inline void spawn(F &&func, A &&...args) { } template -inline void yield_in(S &sched) { +inline void yield(S &sched) { sched.yield(); } @@ -637,7 +654,7 @@ inline void yield() { } template -inline channel make_channel_in(S &sched) { +inline channel make_channel(S &sched) { return channel{[&sched]() { return sched.make_condition(); }};