-
Notifications
You must be signed in to change notification settings - Fork 23
Task migration #276
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
Draft
JorgeV92
wants to merge
12
commits into
bemanproject:main
Choose a base branch
from
JorgeV92:task-migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Task migration #276
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
35d1009
task module
JorgeV92 ded17af
remove double error_types_of.hpp
JorgeV92 4448d21
add allocator_support before update
JorgeV92 56d07f1
update allocator_support P3980R1
JorgeV92 6c00d7a
added task_scheduler and infallible_scheduler
JorgeV92 2a1a968
fixed missing modules import
JorgeV92 b736bdd
reorder imports for task_scheduler.test
JorgeV92 d19b37d
fix some errors in format
JorgeV92 49d8856
fix some errors
JorgeV92 e827e58
fix format
JorgeV92 59c426c
Merge branch 'main' into task-migration
dietmarkuehl 50615ea
Remove completion.hpp from original place in CMakeLists.txt
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
6 changes: 3 additions & 3 deletions
6
...e/beman/execution/detail/allocator_of.hpp → ...an/execution/detail/task/allocator_of.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
149 changes: 149 additions & 0 deletions
149
include/beman/execution/detail/task/allocator_support.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,149 @@ | ||
| // include/beman/execution/detail/task/allocator_support.hpp -*-C++-*- | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_TASK_ALLOCATOR_SUPPORT | ||
| #define INCLUDED_BEMAN_EXECUTION_DETAIL_TASK_ALLOCATOR_SUPPORT | ||
|
|
||
| #include <concepts> | ||
| #include <cstddef> | ||
| #include <memory> | ||
| #include <new> | ||
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| namespace beman::execution::detail { | ||
| struct alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__) allocator_support_allocation_unit { | ||
| std::byte bytes[__STDCPP_DEFAULT_NEW_ALIGNMENT__]; | ||
| }; | ||
|
|
||
| static_assert(sizeof(allocator_support_allocation_unit) == __STDCPP_DEFAULT_NEW_ALIGNMENT__); | ||
| static_assert(alignof(allocator_support_allocation_unit) == __STDCPP_DEFAULT_NEW_ALIGNMENT__); | ||
|
|
||
| struct allocator_support_header { | ||
| void (*deallocate)(void*, std::size_t) noexcept; | ||
| std::size_t count; | ||
| std::size_t palloc_offset; | ||
| }; | ||
|
|
||
| template <typename Alloc> | ||
| using allocator_support_alloc_t = std::remove_cvref_t<Alloc>; | ||
|
|
||
| template <typename Alloc> | ||
| using allocator_support_palloc_t = typename std::allocator_traits< | ||
| allocator_support_alloc_t<Alloc>>::template rebind_alloc<allocator_support_allocation_unit>; | ||
|
|
||
| template <typename Alloc> | ||
| concept allocator_support_allocator_like = requires { typename allocator_support_alloc_t<Alloc>::value_type; }; | ||
|
|
||
| template <typename Allocator, typename Alloc> | ||
| concept allocator_support_allocator_arg = | ||
| allocator_support_allocator_like<Alloc> && requires(allocator_support_alloc_t<Alloc>& alloc, std::size_t size) { | ||
| typename allocator_support_palloc_t<Alloc>; | ||
| typename std::allocator_traits<allocator_support_palloc_t<Alloc>>::pointer; | ||
| requires std::same_as<typename std::allocator_traits<allocator_support_palloc_t<Alloc>>::pointer, | ||
| allocator_support_allocation_unit*>; | ||
| requires(alignof(allocator_support_palloc_t<Alloc>) <= alignof(allocator_support_allocation_unit)); | ||
| allocator_support_palloc_t<Alloc>(alloc); | ||
| std::allocator_traits<allocator_support_palloc_t<Alloc>>::allocate( | ||
| std::declval<allocator_support_palloc_t<Alloc>&>(), size); | ||
| }; | ||
|
|
||
| /*! | ||
| * \brief Utility adding allocator support to type by embedding the allocator | ||
| * \headerfile beman/execution/task.hpp <beman/execution/task.hpp> | ||
| * | ||
| * To add allocator support using this class just publicly inherit from | ||
| * allocator_support<Allocator, YourPromiseType>. This utility is probably | ||
| * only useful for coroutine promise types. | ||
| * | ||
| * This struct is a massive hack, primarily support allocators for coroutines. | ||
| * The memory for coroutines is implicitly managed and there isn't a way to | ||
| * provide the memory directly. Instead, the promise_type can overload an | ||
| * operator new and use a leading std::allocator_arg/allocator pair when it | ||
| * is present. Even worse, the operator delete only gets passed a pointer to | ||
| * delete and a size. To determine the correct allocator the operator delete | ||
| * stores a type-erased deallocation header and the rebound allocator in the | ||
| * allocation block. | ||
| */ | ||
| template <typename Allocator> | ||
| struct allocator_support { | ||
| static std::size_t align_up(std::size_t value, std::size_t alignment) { | ||
| return ((value + alignment - 1u) / alignment) * alignment; | ||
| } | ||
|
|
||
| static std::size_t header_offset(std::size_t size) { | ||
| return allocator_support::align_up(size, alignof(allocator_support_header)); | ||
| } | ||
|
|
||
| static allocator_support_header* get_header(void* ptr, std::size_t size) { | ||
| ptr = static_cast<std::byte*>(ptr) + allocator_support::header_offset(size); | ||
| return ::std::launder(reinterpret_cast<allocator_support_header*>(ptr)); | ||
| } | ||
|
|
||
| template <typename PAlloc> | ||
| static void deallocate_with(void* ptr, std::size_t size) noexcept { | ||
| using palloc_traits = std::allocator_traits<PAlloc>; | ||
|
|
||
| allocator_support_header* header{allocator_support::get_header(ptr, size)}; | ||
| auto* palloc_ptr{ | ||
| ::std::launder(reinterpret_cast<PAlloc*>(static_cast<std::byte*>(ptr) + header->palloc_offset))}; | ||
| PAlloc palloc{*palloc_ptr}; | ||
| std::size_t count{header->count}; | ||
| palloc_ptr->~PAlloc(); | ||
| palloc_traits::deallocate(palloc, static_cast<allocator_support_allocation_unit*>(ptr), count); | ||
| } | ||
|
|
||
| template <typename Alloc> | ||
| requires allocator_support_allocator_arg<Allocator, Alloc> | ||
| static void* allocate(std::size_t size, Alloc alloc) { | ||
| using palloc_t = allocator_support_palloc_t<Alloc>; | ||
| using palloc_traits = std::allocator_traits<palloc_t>; | ||
|
|
||
| palloc_t palloc{alloc}; | ||
| std::size_t header_offset{allocator_support::header_offset(size)}; | ||
| std::size_t palloc_offset{ | ||
| allocator_support::align_up(header_offset + sizeof(allocator_support_header), alignof(palloc_t))}; | ||
| std::size_t count{(palloc_offset + sizeof(palloc_t) + sizeof(allocator_support_allocation_unit) - 1u) / | ||
| sizeof(allocator_support_allocation_unit)}; | ||
|
|
||
| allocator_support_allocation_unit* ptr{palloc_traits::allocate(palloc, count)}; | ||
| try { | ||
| new (static_cast<std::byte*>(static_cast<void*>(ptr)) + header_offset) | ||
| allocator_support_header{&allocator_support::deallocate_with<palloc_t>, count, palloc_offset}; | ||
| new (static_cast<std::byte*>(static_cast<void*>(ptr)) + palloc_offset) palloc_t(palloc); | ||
| } catch (...) { | ||
| palloc_traits::deallocate(palloc, ptr, count); | ||
| throw; | ||
| } | ||
| return ptr; | ||
| } | ||
|
|
||
| static void* operator new(std::size_t size) { return allocator_support::allocate(size, Allocator{}); } | ||
|
|
||
| template <typename Alloc, typename... A> | ||
| requires allocator_support_allocator_arg<Allocator, Alloc> | ||
| static void* operator new(std::size_t size, std::allocator_arg_t, Alloc alloc, A&&...) { | ||
| return allocator_support::allocate(size, alloc); | ||
| } | ||
|
|
||
| template <typename This, typename Alloc, typename... A> | ||
| requires allocator_support_allocator_arg<Allocator, Alloc> | ||
| static void* operator new(std::size_t size, const This&, std::allocator_arg_t, Alloc alloc, A&&...) { | ||
| return allocator_support::allocate(size, alloc); | ||
| } | ||
|
|
||
| template <typename... A> | ||
| static void operator delete(void* ptr, std::size_t size, const A&...) noexcept { | ||
| allocator_support::operator delete(ptr, size); | ||
| } | ||
| static void operator delete(void* ptr, std::size_t size) noexcept { | ||
| allocator_support::get_header(ptr, size)->deallocate(ptr, size); | ||
| } | ||
| }; | ||
| } // namespace beman::execution::detail | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| #endif |
6 changes: 3 additions & 3 deletions
6
...ude/beman/execution/detail/completion.hpp → ...eman/execution/detail/task/completion.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
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
6 changes: 3 additions & 3 deletions
6
...beman/execution/detail/find_allocator.hpp → .../execution/detail/task/find_allocator.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
6 changes: 3 additions & 3 deletions
6
include/beman/execution/detail/handle.hpp → ...de/beman/execution/detail/task/handle.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
58 changes: 58 additions & 0 deletions
58
include/beman/execution/detail/task/infallible_scheduler.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,58 @@ | ||
| // include/beman/execution/detail/task/infallible_scheduler.hpp -*-C++-*- | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_TASK_INFALLIBLE_SCHEDULER | ||
| #define INCLUDED_BEMAN_EXECUTION_DETAIL_TASK_INFALLIBLE_SCHEDULER | ||
|
|
||
| #include <beman/execution/detail/common.hpp> | ||
| #ifdef BEMAN_HAS_IMPORT_STD | ||
| import std; | ||
| #else | ||
| #include <concepts> | ||
| #include <utility> | ||
| #endif | ||
| #ifdef BEMAN_HAS_MODULES | ||
| import beman.execution.detail.completion_signatures; | ||
| import beman.execution.detail.completion_signatures_of_t; | ||
| import beman.execution.detail.env; | ||
| import beman.execution.detail.schedule; | ||
| import beman.execution.detail.scheduler; | ||
| import beman.execution.detail.set_stopped; | ||
| import beman.execution.detail.set_value; | ||
| import beman.execution.detail.stop_token_of_t; | ||
| import beman.execution.detail.unstoppable_token; | ||
| #else | ||
| #include <beman/execution/detail/completion_signatures.hpp> | ||
| #include <beman/execution/detail/completion_signatures_of_t.hpp> | ||
| #include <beman/execution/detail/env.hpp> | ||
| #include <beman/execution/detail/schedule.hpp> | ||
| #include <beman/execution/detail/scheduler.hpp> | ||
| #include <beman/execution/detail/set_stopped.hpp> | ||
| #include <beman/execution/detail/set_value.hpp> | ||
| #include <beman/execution/detail/stop_token_of_t.hpp> | ||
| #include <beman/execution/detail/unstoppable_token.hpp> | ||
| #endif | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| namespace beman::execution::detail { | ||
| template <class Sch, class Env, class... Comp> | ||
| concept completes_with = | ||
| ::std::same_as<::beman::execution::completion_signatures<Comp...>, | ||
| ::beman::execution:: | ||
| completion_signatures_of_t<decltype(::beman::execution::schedule(::std::declval<Sch>())), Env>>; | ||
|
|
||
| template <class Sch, class Env> | ||
| concept infallible_scheduler = | ||
| (::beman::execution::scheduler<Sch>) && | ||
| (::beman::execution::detail::completes_with<Sch, Env, ::beman::execution::set_value_t()> || | ||
| (!::beman::execution::unstoppable_token<::beman::execution::stop_token_of_t<Env>> && | ||
| (::beman::execution::detail:: | ||
| completes_with<Sch, Env, ::beman::execution::set_value_t(), ::beman::execution::set_stopped_t()> || | ||
| ::beman::execution::detail:: | ||
| completes_with<Sch, Env, ::beman::execution::set_stopped_t(), ::beman::execution::set_value_t()>))); | ||
| } // namespace beman::execution::detail | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| #endif |
6 changes: 3 additions & 3 deletions
6
include/beman/execution/detail/logger.hpp → ...de/beman/execution/detail/task/logger.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
11 changes: 8 additions & 3 deletions
11
include/beman/execution/detail/poly.hpp → include/beman/execution/detail/task/poly.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
6 changes: 3 additions & 3 deletions
6
...de/beman/execution/detail/promise_env.hpp → ...man/execution/detail/task/promise_env.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
6 changes: 3 additions & 3 deletions
6
include/beman/execution/detail/state_rep.hpp → ...beman/execution/detail/task/state_rep.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
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
6 changes: 3 additions & 3 deletions
6
include/beman/execution/detail/sub_visit.hpp → ...beman/execution/detail/task/sub_visit.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
Oops, something went wrong.
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.
This comment on the trailing
#endifseems unusual. Maybe instead of fixing it remove it? In theory these comments should be added/removed by a code formatting tool likeclang-format(I don't know if that actually does such transformations).