-
Notifications
You must be signed in to change notification settings - Fork 12
Task allocation #74
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
Task allocation #74
Changes from all commits
f927694
a87856f
daacb37
1930e4d
dbdf2c0
31c2b47
ab16c4a
fa3f441
611a313
520072e
1bab4fb
a67dd56
89dd18e
e657f74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <beman/task/detail/promise_base.hpp> | ||
| #include <beman/task/detail/allocator_of.hpp> | ||
| #include <beman/task/detail/state_base.hpp> | ||
| #include <beman/task/detail/inline_scheduler.hpp> | ||
| #include <beman/execution/execution.hpp> | ||
|
|
@@ -48,6 +49,7 @@ struct env { | |
| template <typename T, typename... E> | ||
| struct state : bt::state_base<T, env<E...>> { | ||
| using Environment = env<E...>; | ||
| using allocator_type = ::beman::task::detail::allocator_of_t<Environment>; | ||
| using stop_source_type = ::beman::task::detail::stop_source_of_t<Environment>; | ||
| using stop_token_type = decltype(std::declval<stop_source_type>().get_token()); | ||
| using scheduler_type = ::beman::task::detail::scheduler_of_t<Environment>; | ||
|
|
@@ -62,6 +64,7 @@ struct state : bt::state_base<T, env<E...>> { | |
| this->completed = true; | ||
| return std::noop_coroutine(); | ||
| } | ||
| allocator_type do_get_allocator() override { return allocator_type{}; } | ||
| stop_token_type do_get_stop_token() override { | ||
| this->token = true; | ||
| return this->source.get_token(); | ||
|
Comment on lines
50
to
70
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <beman/task/detail/promise_type.hpp> | ||
| #include <beman/task/detail/allocator_of.hpp> | ||
| #include <beman/task/detail/task_scheduler.hpp> | ||
| #include <beman/task/detail/inline_scheduler.hpp> | ||
| #include <beman/execution/execution.hpp> | ||
|
|
@@ -128,7 +129,8 @@ struct test_error : std::exception { | |
|
|
||
| struct test_task : beman::task::detail::state_base<int, environment> { | ||
|
|
||
| using promise_type = beman::task::detail::promise_type<test_task, int, environment>; | ||
| using promise_type = ::beman::task::detail::promise_type<test_task, int, environment>; | ||
| using allocator_type = ::beman::task::detail::allocator_of_t<environment>; | ||
|
|
||
| beman::task::detail::handle<promise_type> handle; | ||
| explicit test_task(beman::task::detail::handle<promise_type> h) : handle(std::move(h)) {} | ||
|
|
@@ -153,6 +155,7 @@ struct test_task : beman::task::detail::state_base<int, environment> { | |
| this->latch.count_down(); | ||
| return std::noop_coroutine(); | ||
| } | ||
| allocator_type do_get_allocator() override { return allocator_type{}; } | ||
| stop_token_type do_get_stop_token() override { return this->source.get_token(); } | ||
| environment& do_get_environment() override { return this->env; } | ||
|
Comment on lines
130
to
160
|
||
| auto do_get_scheduler() -> scheduler_type override { return scheduler_type(bt::inline_scheduler()); } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
|
|
||
| #include <beman/task/detail/state_base.hpp> | ||
| #include <beman/task/detail/inline_scheduler.hpp> | ||
| #include <beman/task/detail/allocator_of.hpp> | ||
| #ifdef NDEBUG | ||
| #undef NDEBUG | ||
| #endif | ||
|
|
@@ -16,6 +17,7 @@ namespace { | |
| struct environment {}; | ||
|
|
||
| struct state : beman::task::detail::state_base<int, environment> { | ||
| using allocator_type = ::beman::task::detail::allocator_of_t<environment>; | ||
| stop_source_type source; | ||
| environment env; | ||
| bool completed{}; | ||
|
|
@@ -26,6 +28,7 @@ struct state : beman::task::detail::state_base<int, environment> { | |
| this->completed = true; | ||
| return std::noop_coroutine(); | ||
| } | ||
| allocator_type do_get_allocator() override { return allocator_type{}; } | ||
| stop_token_type do_get_stop_token() override { | ||
|
Comment on lines
19
to
32
|
||
| this->token = true; | ||
| return this->source.get_token(); | ||
|
|
||
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.
promise_type::get_allocator()now forwards tothis->get_state()->get_allocator()but unlikeget_environment()it doesn't assert thatget_state()is non-null. Ifget_allocatoris queried beforestart()/set_state()(e.g. viaget_env()), this will dereference a null state pointer. Consider adding anassert(this->get_state())(or a safe fallback allocator) similar toget_environment().