From 547cfc842c400d475ee521338ba9a0b7343a6689 Mon Sep 17 00:00:00 2001 From: Lucian Radu Teodorescu Date: Sat, 17 Aug 2024 16:23:59 +0300 Subject: [PATCH] Combine `bulk_item_receiver` with `receiver`, so that we don't need to pass the same receiver object twice. --- .../exec/__detail/__system_context_default_impl.hpp | 9 ++++----- .../__detail/__system_context_replaceability_api.hpp | 11 ++++------- include/exec/system_context.hpp | 5 ++--- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/include/exec/__detail/__system_context_default_impl.hpp b/include/exec/__detail/__system_context_default_impl.hpp index 449a39a38..d9f2f156d 100644 --- a/include/exec/__detail/__system_context_default_impl.hpp +++ b/include/exec/__detail/__system_context_default_impl.hpp @@ -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(__idx)); + __r_->start(static_cast(__idx)); } }; @@ -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(); diff --git a/include/exec/__detail/__system_context_replaceability_api.hpp b/include/exec/__detail/__system_context_replaceability_api.hpp index ad613e032..3beb5618c 100644 --- a/include/exec/__detail/__system_context_replaceability_api.hpp +++ b/include/exec/__detail/__system_context_replaceability_api.hpp @@ -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; }; @@ -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. diff --git a/include/exec/system_context.hpp b/include/exec/system_context.hpp index 54759238d..d70db99cd 100644 --- a/include/exec/system_context.hpp +++ b/include/exec/system_context.hpp @@ -233,8 +233,7 @@ namespace exec { /// Derived class will properly implement the receiver methods. template 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. @@ -337,7 +336,7 @@ namespace exec { system_context_replaceability::storage __storage{ &__state_.__preallocated_, sizeof(__state_.__preallocated_)}; __state_.__snd_.__scheduler_->bulk_schedule( - static_cast(__state_.__snd_.__size_), __storage, __r, __r); + static_cast(__state_.__snd_.__size_), __storage, __r); } /// Invoked when the previous sender completes with "stopped" to stop the entire work.