-
Notifications
You must be signed in to change notification settings - Fork 17
Affine on #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Affine on #199
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
545f4ab
enhanced run_loop to have an infallible scheduler
dietmarkuehl c3a40ba
clang format
dietmarkuehl 838d5da
don't use set_stopped for unstoppable tokens
dietmarkuehl 6ee955a
removed remaining uses of set_error in run_loop
dietmarkuehl f499931
try to avoid set_error in let* based on noexcept
dietmarkuehl e6ec484
fix run_loop's use of empty_env
dietmarkuehl 34ccc99
implemented a basic affine_on
dietmarkuehl b4db2bb
added the various constraints and customization to affine_on
dietmarkuehl 0aab830
added some documentation to affine_on
dietmarkuehl 5279bf1
minor fixes to the affine_on implementation
dietmarkuehl 9013097
added some tests and an example affine_on customization
dietmarkuehl 0ae4384
added a few affine_on customizations
dietmarkuehl e306f20
restore empty CMakeLists.txt for code examples
dietmarkuehl 8650193
fix two minor issues discovered by CI
dietmarkuehl e4be2b8
fix a formatting issue
dietmarkuehl 475fc41
remove duplicate headers
dietmarkuehl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| // include/beman/execution/detail/affine_on.hpp -*-C++-*- | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #ifndef INCLUDED_INCLUDE_BEMAN_EXECUTION_DETAIL_AFFINE_ON | ||
| #define INCLUDED_INCLUDE_BEMAN_EXECUTION_DETAIL_AFFINE_ON | ||
|
|
||
| #include <beman/execution/detail/env.hpp> | ||
| #include <beman/execution/detail/forward_like.hpp> | ||
| #include <beman/execution/detail/fwd_env.hpp> | ||
| #include <beman/execution/detail/get_domain_early.hpp> | ||
| #include <beman/execution/detail/get_scheduler.hpp> | ||
| #include <beman/execution/detail/get_stop_token.hpp> | ||
| #include <beman/execution/detail/join_env.hpp> | ||
| #include <beman/execution/detail/make_sender.hpp> | ||
| #include <beman/execution/detail/never_stop_token.hpp> | ||
| #include <beman/execution/detail/prop.hpp> | ||
| #include <beman/execution/detail/schedule_from.hpp> | ||
| #include <beman/execution/detail/scheduler.hpp> | ||
| #include <beman/execution/detail/sender.hpp> | ||
| #include <beman/execution/detail/sender_adaptor.hpp> | ||
| #include <beman/execution/detail/sender_adaptor_closure.hpp> | ||
| #include <beman/execution/detail/sender_for.hpp> | ||
| #include <beman/execution/detail/sender_has_affine_on.hpp> | ||
| #include <beman/execution/detail/tag_of_t.hpp> | ||
| #include <beman/execution/detail/transform_sender.hpp> | ||
| #include <beman/execution/detail/write_env.hpp> | ||
|
|
||
| #include <concepts> | ||
| #include <type_traits> | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| namespace beman::execution::detail { | ||
|
|
||
| /** | ||
| * @brief The affine_on_t struct is a sender adaptor closure that transforms a sender | ||
| * to complete on the scheduler obtained from the receiver's environment. | ||
| * | ||
| * This adaptor implements scheduler affinity to adapt a sender to complete on the | ||
| * scheduler obtained the receiver's environment. The get_scheduler query is used | ||
| * to obtain the scheduler on which the sender gets started. | ||
| */ | ||
| struct affine_on_t : ::beman::execution::sender_adaptor_closure<affine_on_t> { | ||
| /** | ||
| * @brief Adapt a sender with affine_on. | ||
| * | ||
| * @tparam Sender The deduced type of the sender to be transformed. | ||
| * @param sender The sender to be transformed. | ||
| * @return An adapted sender to complete on the scheduler it was started on. | ||
| */ | ||
| template <::beman::execution::sender Sender> | ||
| auto operator()(Sender&& sender) const { | ||
| return ::beman::execution::detail::transform_sender( | ||
| ::beman::execution::detail::get_domain_early(sender), | ||
| ::beman::execution::detail::make_sender( | ||
| *this, ::beman::execution::env<>{}, ::std::forward<Sender>(sender))); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Overload for creating a sender adaptor from affine_on. | ||
| * | ||
| * @return A sender adaptor for the affine_on_t. | ||
| */ | ||
| auto operator()() const { return ::beman::execution::detail::sender_adaptor{*this}; } | ||
|
|
||
| /** | ||
| * @brief affine_on is implemented by transforming it into a use of schedule_from. | ||
| * | ||
| * The constraints ensure that the environment provides a scheduler which is | ||
| * infallible and, thus, can be used to guarantee completion on the correct | ||
| * scheduler. | ||
| * | ||
| * The implementation first tries to see if the child sender's tag has a custom | ||
| * affine_on implementation. If it does, that is used. Otherwise, the default | ||
| * implementation gets a scheduler from the environment and uses schedule_from | ||
| * to adapt the sender to complete on that scheduler. | ||
| * | ||
| * @tparam Sender The type of the sender to be transformed. | ||
| * @tparam Env The type of the environment providing the scheduler. | ||
| * @param sender The sender to be transformed. | ||
| * @param env The environment providing the scheduler. | ||
| * @return A transformed sender that is affined to the scheduler. | ||
| */ | ||
| template <::beman::execution::sender Sender, typename Env> | ||
| requires ::beman::execution::detail::sender_for<Sender, affine_on_t> && requires(const Env& env) { | ||
| { ::beman::execution::get_scheduler(env) } -> ::beman::execution::scheduler; | ||
| { ::beman::execution::schedule(::beman::execution::get_scheduler(env)) } -> ::beman::execution::sender; | ||
| { | ||
| ::beman::execution::get_completion_signatures( | ||
| ::beman::execution::schedule(::beman::execution::get_scheduler(env)), | ||
| ::beman::execution::detail::join_env( | ||
| ::beman::execution::env{::beman::execution::prop{::beman::execution::get_stop_token, | ||
| ::beman::execution::never_stop_token{}}}, | ||
| env)) | ||
| } -> ::std::same_as<::beman::execution::completion_signatures<::beman::execution::set_value_t()>>; | ||
| } | ||
| static auto transform_sender(Sender&& sender, const Env& env) { | ||
| [[maybe_unused]] auto& [tag, data, child] = sender; | ||
| using child_tag_t = ::beman::execution::tag_of_t<::std::remove_cvref_t<decltype(child)>>; | ||
|
|
||
| #if 0 | ||
| if constexpr (requires(const child_tag_t& t) { | ||
| { | ||
| t.affine_on(::beman::execution::detail::forward_like<Sender>(child), env) | ||
| } -> ::beman::execution::sender; | ||
| }) | ||
| #else | ||
| if constexpr (::beman::execution::detail::nested_sender_has_affine_on<Sender, Env>) | ||
| #endif | ||
| { | ||
| return child_tag_t{}.affine_on(::beman::execution::detail::forward_like<Sender>(child), env); | ||
| } else { | ||
| return ::beman::execution::write_env( | ||
| ::beman::execution::schedule_from( | ||
| ::beman::execution::get_scheduler(env), | ||
| ::beman::execution::write_env(::beman::execution::detail::forward_like<Sender>(child), env)), | ||
| ::beman::execution::detail::join_env( | ||
| ::beman::execution::env{::beman::execution::prop{::beman::execution::get_stop_token, | ||
| ::beman::execution::never_stop_token{}}}, | ||
| env)); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| } // namespace beman::execution::detail | ||
|
|
||
| namespace beman::execution { | ||
| /** | ||
| * @brief affine_on is a CPO, used to adapt a sender to complete on the scheduler | ||
| * it got started on which is derived from get_scheduler on the receiver's environment. | ||
| */ | ||
| using beman::execution::detail::affine_on_t; | ||
| inline constexpr affine_on_t affine_on{}; | ||
| } // namespace beman::execution | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
include/beman/execution/detail/nested_sender_has_affine_on.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // include/beman/execution/detail/nested_sender_has_affine_on.hpp -*-C++-*- | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #ifndef INCLUDED_INCLUDE_BEMAN_EXECUTION_DETAIL_NESTED_SENDER_HAS_AFFINE_ON | ||
| #define INCLUDED_INCLUDE_BEMAN_EXECUTION_DETAIL_NESTED_SENDER_HAS_AFFINE_ON | ||
|
|
||
| #include <beman/execution/detail/sender_has_affine_on.hpp> | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| namespace beman::execution::detail { | ||
| template <typename Sender, typename Env> | ||
| concept nested_sender_has_affine_on = requires(Sender&& sndr, const Env& env) { | ||
| { sndr.template get<2>() } -> ::beman::execution::detail::sender_has_affine_on<Env>; | ||
| }; | ||
| } // namespace beman::execution::detail | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // include/beman/execution/detail/sender_has_affine_on.hpp -*-C++-*- | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #ifndef INCLUDED_INCLUDE_BEMAN_EXECUTION_DETAIL_SENDER_HAS_AFFINE_ON | ||
| #define INCLUDED_INCLUDE_BEMAN_EXECUTION_DETAIL_SENDER_HAS_AFFINE_ON | ||
|
|
||
| #include <beman/execution/detail/sender.hpp> | ||
| #include <utility> | ||
| #include <type_traits> | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| namespace beman::execution::detail { | ||
| template <typename Sender, typename Env> | ||
| concept sender_has_affine_on = | ||
| beman::execution::sender<::std::remove_cvref_t<Sender>> && requires(Sender&& sndr, const Env& env) { | ||
| sndr.template get<0>(); | ||
| { sndr.template get<0>().affine_on(std::forward<Sender>(sndr), env) } -> ::beman::execution::sender; | ||
| }; | ||
| } // namespace beman::execution::detail | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented-out code should be removed. If the alternative implementation using
#if 0is no longer needed, remove lines 102-108 and 110 entirely, keeping only the active implementation.