Skip to content

Commit

Permalink
Combine bulk_item_receiver with receiver, so that we don't need t…
Browse files Browse the repository at this point in the history
…o pass the same receiver object twice.
  • Loading branch information
lucteo committed Aug 17, 2024
1 parent 29e5893 commit 547cfc8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
9 changes: 4 additions & 5 deletions include/exec/__detail/__system_context_default_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ namespace exec::__system_context_default_impl {

//! Functor called by the `bulk` operation; sends a `start` signal to the frontend.
struct __bulk_functor {
bulk_item_receiver* __item_r_;
bulk_item_receiver* __r_;

void operator()(unsigned long __idx) const noexcept {
__item_r_->start(static_cast<uint32_t>(__idx));
__r_->start(static_cast<uint32_t>(__idx));
}
};

Expand All @@ -163,11 +163,10 @@ namespace exec::__system_context_default_impl {
void bulk_schedule(
uint32_t __size,
storage __storage,
receiver* __r,
bulk_item_receiver* __item_r) noexcept override {
bulk_item_receiver* __r) noexcept override {
try {
auto __sndr =
stdexec::bulk(stdexec::schedule(__pool_scheduler_), __size, __bulk_functor{__item_r});
stdexec::bulk(stdexec::schedule(__pool_scheduler_), __size, __bulk_functor{__r});
auto __os =
__bulk_schedule_operation_t::__construct_maybe_alloc(__storage, __r, std::move(__sndr));
__os->start();
Expand Down
11 changes: 4 additions & 7 deletions include/exec/__detail/__system_context_replaceability_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ namespace exec::system_context_replaceability {
virtual void set_stopped() noexcept = 0;
};

/// Interface for receiving bulk item signals.
struct bulk_item_receiver {
virtual ~bulk_item_receiver() = default;

/// Receiver for bulk sheduling operations.
struct bulk_item_receiver : receiver {
/// Called for each item of a bulk operation, possible on different threads.
virtual void start(uint32_t) noexcept = 0;
};
Expand All @@ -85,9 +83,8 @@ namespace exec::system_context_replaceability {

/// Schedule work on system scheduler, calling `__r` when done and using `__s` for preallocated memory.
virtual void schedule(storage __s, receiver* __r) noexcept = 0;
/// Schedule bulk work of size `__n` on system scheduler, calling `__br` for each item, calling `__r` when done and using `__s` for preallocated memory.
virtual void
bulk_schedule(uint32_t __n, storage __s, receiver* __r, bulk_item_receiver* __br) noexcept = 0;
/// Schedule bulk work of size `__n` on system scheduler, calling `__r` for each item and then when done, and using `__s` for preallocated memory.
virtual void bulk_schedule(uint32_t __n, storage __s, bulk_item_receiver* __r) noexcept = 0;
};

/// Implementation-defined mechanism for replacing the system scheduler backend at run-time.
Expand Down
5 changes: 2 additions & 3 deletions include/exec/system_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ namespace exec {
/// Derived class will properly implement the receiver methods.
template <class _Previous>
struct __forward_args_receiver
: system_context_replaceability::receiver
, system_context_replaceability::bulk_item_receiver {
: system_context_replaceability::bulk_item_receiver {
using __storage_t = __detail::__sender_data_t<_Previous>;

/// Pointer to the `__system_bulk_op` object.
Expand Down Expand Up @@ -337,7 +336,7 @@ namespace exec {
system_context_replaceability::storage __storage{
&__state_.__preallocated_, sizeof(__state_.__preallocated_)};
__state_.__snd_.__scheduler_->bulk_schedule(
static_cast<uint32_t>(__state_.__snd_.__size_), __storage, __r, __r);
static_cast<uint32_t>(__state_.__snd_.__size_), __storage, __r);
}

/// Invoked when the previous sender completes with "stopped" to stop the entire work.
Expand Down

0 comments on commit 547cfc8

Please sign in to comment.