Skip to content

Commit

Permalink
the let_* algorithms have a dependent domain, which causes a recursiv…
Browse files Browse the repository at this point in the history
…e tree transformation
  • Loading branch information
ericniebler committed Oct 26, 2023
1 parent e0b55ce commit 6eeab9e
Show file tree
Hide file tree
Showing 4 changed files with 281 additions and 128 deletions.
40 changes: 34 additions & 6 deletions include/exec/static_thread_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ namespace exec {
void (*__execute)(task_base*, std::uint32_t tid) noexcept;
};

template <class>
struct not_a_sender {
using is_sender = void;
};

class static_thread_pool {
template <class ReceiverId>
class operation;
Expand Down Expand Up @@ -100,21 +105,44 @@ namespace exec {
static_thread_pool& pool_;
};

public:
struct domain {
// For eager customization
template <stdexec::sender_expr_for<stdexec::bulk_t> Sender>
auto transform_sender(Sender&& sndr) const noexcept {
auto sched = stdexec::get_completion_scheduler<stdexec::set_value_t>(
stdexec::get_env(sndr));
return stdexec::apply_sender((Sender&&) sndr, transform_bulk{*sched.pool_});
if constexpr (stdexec::__completes_on<Sender, static_thread_pool>) {
auto sched = stdexec::get_completion_scheduler<stdexec::set_value_t>(
stdexec::get_env(sndr));
return stdexec::apply_sender((Sender&&) sndr, transform_bulk{*sched.pool_});
} else {
static_assert(
stdexec::__completes_on<Sender, static_thread_pool>,
"No static_thread_pool instance can be found in the sender's environment "
"on which to schedule bulk work.");
return not_a_sender<stdexec::__name_of<Sender>>();
}
STDEXEC_UNREACHABLE();
}

// transform the generic bulk sender into a parallel thread-pool bulk sender
template <stdexec::sender_expr_for<stdexec::bulk_t> Sender, class Env>
requires stdexec::__callable<stdexec::get_scheduler_t, Env>
auto transform_sender(Sender&& sndr, const Env& env) const noexcept {
auto sched = stdexec::get_scheduler(env);
return stdexec::apply_sender((Sender&&) sndr, transform_bulk{*sched.pool_});
if constexpr (stdexec::__completes_on<Sender, static_thread_pool>) {
auto sched = stdexec::get_completion_scheduler<stdexec::set_value_t>(
stdexec::get_env(sndr));
return stdexec::apply_sender((Sender&&) sndr, transform_bulk{*sched.pool_});
} else if constexpr (stdexec::__starts_on<Sender, static_thread_pool, Env>) {
auto sched = stdexec::get_scheduler(env);
return stdexec::apply_sender((Sender&&) sndr, transform_bulk{*sched.pool_});
} else {
static_assert( //
stdexec::__starts_on<Sender, static_thread_pool, Env>
|| stdexec::__completes_on<Sender, static_thread_pool>,
"No static_thread_pool instance can be found in the sender's or receiver's "
"environment on which to schedule bulk work.");
return not_a_sender<stdexec::__name_of<Sender>>();
}
STDEXEC_UNREACHABLE();
}
};

Expand Down
8 changes: 8 additions & 0 deletions include/stdexec/__detail/__execution_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ namespace stdexec {
using __transfer_just::transfer_just_t;
extern const transfer_just_t transfer_just;

//////////////////////////////////////////////////////////////////////////////////////////////////
namespace __bulk {
struct bulk_t;
}

using __bulk::bulk_t;
extern const bulk_t bulk;

//////////////////////////////////////////////////////////////////////////////////////////////////
namespace __on_v2 {
struct on_t;
Expand Down
3 changes: 3 additions & 0 deletions include/stdexec/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ namespace stdexec {
template <class _Ty>
concept __nothrow_decay_copyable = __nothrow_constructible_from<__decay_t<_Ty>, _Ty>;

template <class _Ty, class _Up>
concept __decays_to_derived_from = derived_from<__decay_t<_Ty>, _Up>;

} // namespace stdexec

// #if !STDEXEC_HAS_STD_CONCEPTS_HEADER()
Expand Down
Loading

0 comments on commit 6eeab9e

Please sign in to comment.