Skip to content

Commit 71d6518

Browse files
committed
restored most of the scheduling functionality
1 parent 8db3826 commit 71d6518

File tree

13 files changed

+150
-191
lines changed

13 files changed

+150
-191
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets)
3434

3535
FetchContent_Declare(
3636
execution
37-
# SOURCE_DIR <path-to>/execution
38-
GIT_REPOSITORY https://github.com/bemanproject/execution
39-
GIT_TAG 578c05
37+
SOURCE_DIR /Users/kuehl/src/execution
38+
# GIT_REPOSITORY https://github.com/bemanproject/execution
39+
# GIT_TAG 578c05
4040
)
4141
FetchContent_MakeAvailable(execution)
4242
FetchContent_Declare(

examples/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3+
set(ALL_EXAMPLES co_await-task)
34
set(ALL_EXAMPLES
45
co_await-task
5-
)
6-
set(xALL_EXAMPLES
7-
co_await-task
86
task_scheduler
97
environment
108
c++now-basic

examples/affinity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static_assert(ex::receiver<test_receiver>);
2323

2424
std::ostream& fmt_id(std::ostream& out) { return out << std::this_thread::get_id(); }
2525

26-
struct non_affine : ex::default_context {
26+
struct non_affine {
2727
using scheduler_type = ex::inline_scheduler;
2828
};
2929
} // namespace

examples/co_await-task.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ auto inner() -> ex::task<> {
1717
auto outer() -> ex::task<> {
1818
beman::task::detail::logger log("outer");
1919
for (int i{}; i < 10; ++i) {
20-
co_await inner().as_awaitable();
20+
co_await inner();
2121
log.log("inner_awaited");
2222
}
2323
co_return;

include/beman/lazy/lazy.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
// ----------------------------------------------------------------------------
1010

1111
namespace beman::lazy {
12-
template <typename T = void, typename Context = ::beman::task::default_context>
12+
template <typename T = void, typename Context = ::beman::task::default_environment>
1313
using lazy = ::beman::task::detail::task<T, Context>;
1414
}
1515

1616
namespace beman::execution {
17-
template <typename T = void, typename Context = ::beman::task::default_context>
17+
template <typename T = void, typename Context = ::beman::task::default_environment>
1818
using lazy [[deprecated("beman::execution::lazy has been renamed to beman::execution::task")]] =
1919
::beman::execution::task<T, Context>;
2020
}

include/beman/task/detail/awaiter.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,37 @@ template <typename Env, typename Promise>
1717
class awaiter : public ::beman::task::detail::state_base<Env> {
1818
public:
1919
using stop_token_type = typename ::beman::task::detail::state_base<Env>::stop_token_type;
20+
using scheduler_type = typename ::beman::task::detail::state_base<Env>::scheduler_type;
2021

2122
explicit awaiter(::beman::task::detail::handle<Promise> h) : handle(::std::move(h)) {}
2223
constexpr auto await_ready() const noexcept -> bool { return false; }
2324
template <typename PP>
2425
auto await_suspend(::std::coroutine_handle<PP> parent) noexcept {
2526
::beman::task::detail::logger log("awaiter::suspend");
27+
this->scheduler.emplace(
28+
this->template from_env<scheduler_type>(::beman::execution::get_env(parent.promise())));
2629
this->parent = ::std::move(parent);
2730
assert(this->parent);
2831
return this->handle.start(this);
2932
}
3033
auto await_resume() { ::beman::task::detail::logger l("awaiter::await_resume()"); }
34+
auto parent_handle() -> ::std::coroutine_handle<> { return ::std::move(this->parent); }
3135

3236
private:
3337
auto do_complete() -> std::coroutine_handle<> override {
3438
::beman::task::detail::logger l("awaiter::complete()");
3539
assert(this->parent);
3640
return ::std::move(this->parent);
3741
}
42+
auto do_get_scheduler() -> scheduler_type override { return *this->scheduler; }
43+
auto do_set_scheduler(scheduler_type other) -> scheduler_type override {
44+
return ::std::exchange(*this->scheduler, other);
45+
}
3846
auto do_get_stop_token() -> stop_token_type override { return {}; }
3947
auto do_get_context() -> Env& override { return this->env; }
4048

41-
::beman::task::detail::logger l{"awaiter"};
4249
Env env;
50+
::std::optional<scheduler_type> scheduler;
4351
::beman::task::detail::handle<Promise> handle;
4452
::std::coroutine_handle<> parent{};
4553
};

include/beman/task/detail/final_awaiter.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
#ifndef INCLUDED_INCLUDE_BEMAN_TASK_DETAIL_FINAL_AWAITER
55
#define INCLUDED_INCLUDE_BEMAN_TASK_DETAIL_FINAL_AWAITER
66

7+
#include <beman/task/detail/state_base.hpp>
8+
#include <beman/task/detail/logger.hpp>
79
#include <coroutine>
810

911
// ----------------------------------------------------------------------------
1012

1113
namespace beman::task::detail {
1214

1315
struct final_awaiter {
14-
static constexpr bool await_ready() noexcept { return false; }
16+
static constexpr auto await_ready() noexcept -> bool { return false; }
1517
template <typename Promise>
16-
static void await_suspend(std::coroutine_handle<Promise> handle) noexcept {
17-
handle.promise().notify_complete();
18+
static auto await_suspend(std::coroutine_handle<Promise> handle) noexcept {
19+
::beman::task::detail::logger l("final_awaiter::await_suspend");
20+
return handle.promise().notify_complete();
1821
}
1922
static constexpr void await_resume() noexcept {}
2023
};

include/beman/task/detail/promise_base.hpp

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,6 @@ namespace beman::task::detail {
2323
template <::beman::task::detail::stoppable Stop, typename Value, typename ErrorCompletions>
2424
class promise_base;
2525

26-
#if 0
27-
template <::beman::task::detail::stoppable Stop, typename Value>
28-
requires(not ::std::same_as<Value, void>)
29-
class promise_base<Stop, Value, ::beman::execution::completion_signatures<>>
30-
: public ::beman::task::detail::result_type<Stop, Value> {
31-
public:
32-
/*
33-
* \brief Set the value result.
34-
* \internal
35-
*/
36-
template <typename T>
37-
void return_value(T&& value) {
38-
::beman::task::detail::logger l("promise_base::return_value(T&&)");
39-
this->set_value(::std::forward<T>(value));
40-
}
41-
};
42-
#endif
43-
4426
template <::beman::task::detail::stoppable Stop, typename Value, typename... Error>
4527
requires(not ::std::same_as<Value, void>)
4628
class promise_base<Stop, Value, ::beman::execution::completion_signatures<::beman::execution::set_error_t(Error)...>>
@@ -50,39 +32,21 @@ class promise_base<Stop, Value, ::beman::execution::completion_signatures<::bema
5032
* \brief Set the value result.
5133
* \internal
5234
*/
53-
::beman::task::detail::logger l{"promise_base<T>"};
5435
template <typename T>
5536
void return_value(T&& value) {
5637
::beman::task::detail::logger l("promise_base::return_value(T&&)");
5738
this->set_value(::std::forward<T>(value));
5839
}
5940
};
6041

61-
#if 0
62-
template <typename ::beman::task::detail::stoppable Stop>
63-
class promise_base<Stop, void, ::beman::execution::completion_signatures<>>
64-
: public ::beman::task::detail::result_type<Stop, void_type> {
65-
public:
66-
/*
67-
* \brief Set the value result although without any value.
68-
*/
69-
::beman::task::detail::logger l{"promise_base<void>"};
70-
void return_void() {
71-
::beman::task::detail::logger l("promise_base::return_void()");
72-
this->set_value(void_type{});
73-
}
74-
};
75-
#endif
76-
7742
template <typename ::beman::task::detail::stoppable Stop, typename... Error>
7843
class promise_base<Stop, void, ::beman::execution::completion_signatures<::beman::execution::set_error_t(Error)...>>
7944
: public ::beman::task::detail::result_type<Stop, void_type, Error...> {
8045
public:
8146
/*
8247
* \brief Set the value result although without any value.
8348
*/
84-
::beman::task::detail::logger l{"promise_base<void>"};
85-
void return_void() {
49+
void return_void() {
8650
::beman::task::detail::logger l("promise_base::return_void()");
8751
this->set_value(void_type{});
8852
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// include/beman/task/detail/promise_env.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_INCLUDE_BEMAN_TASK_DETAIL_PROMISE_ENV
5+
#define INCLUDED_INCLUDE_BEMAN_TASK_DETAIL_PROMISE_ENV
6+
7+
#include <beman/execution/execution.hpp>
8+
#include <utility>
9+
10+
// ----------------------------------------------------------------------------
11+
12+
namespace beman::task::detail {
13+
template <typename Promise>
14+
struct promise_env {
15+
const Promise* promise;
16+
17+
auto query(::beman::execution::get_allocator_t) const noexcept -> typename Promise::allocator_type {
18+
return this->promise->get_allocator();
19+
}
20+
auto query(::beman::execution::get_scheduler_t) const noexcept -> typename Promise::scheduler_type {
21+
return this->promise->get_scheduler();
22+
}
23+
auto query(::beman::execution::get_stop_token_t) const noexcept -> typename Promise::stop_token_type {
24+
return this->promise->get_stop_token();
25+
}
26+
27+
template <typename Q, typename... A>
28+
requires requires(const Promise* p, Q q, A&&... a) {
29+
::beman::execution::forwarding_query(q);
30+
q(p->get_context(), std::forward<A>(a)...);
31+
}
32+
auto query(Q q, A&&... a) const noexcept {
33+
return q(promise->get_context(), std::forward<A>(a)...);
34+
}
35+
};
36+
} // namespace beman::task::detail
37+
38+
// ----------------------------------------------------------------------------
39+
40+
#endif

0 commit comments

Comments
 (0)