Skip to content

Commit 11418df

Browse files
authored
Implement get_forward_progress_guarantee (#242)
1 parent 09d5a5c commit 11418df

File tree

6 files changed

+78
-3
lines changed

6 files changed

+78
-3
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// include/beman/execution/detail/get_forward_progress_guarantee.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_GET_FORWARD_PROGRESS_GUARANTEE
5+
#define INCLUDED_BEMAN_EXECUTION_DETAIL_GET_FORWARD_PROGRESS_GUARANTEE
6+
7+
#include <beman/execution/detail/common.hpp>
8+
#include <beman/execution/detail/suppress_push.hpp>
9+
#ifdef BEMAN_HAS_IMPORT_STD
10+
import std;
11+
#else
12+
#include <concepts>
13+
#endif
14+
#ifdef BEMAN_HAS_MODULES
15+
import beman.execution.detail.forwarding_query;
16+
#else
17+
#include <beman/execution/detail/forwarding_query.hpp>
18+
#endif
19+
20+
// ----------------------------------------------------------------------------
21+
22+
namespace beman::execution {
23+
24+
enum class forward_progress_guarantee { concurrent, parallel, weakly_parallel };
25+
26+
struct get_forward_progress_guarantee_t {
27+
template <typename Object>
28+
requires requires(const Object& object, const get_forward_progress_guarantee_t& tag) { object.query(tag); }
29+
auto operator()(const Object& object) const noexcept -> forward_progress_guarantee {
30+
static_assert(::std::same_as<decltype(object.query(*this)), forward_progress_guarantee>);
31+
return object.query(*this);
32+
}
33+
34+
template <typename Object>
35+
auto operator()(const Object&) const noexcept -> forward_progress_guarantee {
36+
return forward_progress_guarantee::weakly_parallel;
37+
}
38+
39+
static constexpr auto query(const ::beman::execution::forwarding_query_t&) noexcept -> bool { return true; }
40+
};
41+
42+
inline constexpr get_forward_progress_guarantee_t get_forward_progress_guarantee{};
43+
} // namespace beman::execution
44+
45+
// ----------------------------------------------------------------------------
46+
47+
#include <beman/execution/detail/suppress_pop.hpp>
48+
49+
#endif // INCLUDED_BEMAN_EXECUTION_DETAIL_GET_FORWARD_PROGRESS_GUARANTEE

include/beman/execution/detail/run_loop.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import beman.execution.detail.completion_signatures;
1919
import beman.execution.detail.env;
2020
import beman.execution.detail.get_completion_scheduler;
2121
import beman.execution.detail.get_env;
22+
import beman.execution.detail.get_forward_progress_guarantee;
2223
import beman.execution.detail.get_stop_token;
2324
import beman.execution.detail.immovable;
2425
import beman.execution.detail.operation_state;
@@ -32,6 +33,7 @@ import beman.execution.detail.unstoppable_token;
3233
#include <beman/execution/detail/completion_signatures.hpp>
3334
#include <beman/execution/detail/get_completion_scheduler.hpp>
3435
#include <beman/execution/detail/get_env.hpp>
36+
#include <beman/execution/detail/get_forward_progress_guarantee.hpp>
3537
#include <beman/execution/detail/get_stop_token.hpp>
3638
#include <beman/execution/detail/immovable.hpp>
3739
#include <beman/execution/detail/operation_state.hpp>
@@ -113,6 +115,11 @@ class run_loop {
113115

114116
auto schedule() noexcept -> sender { return {this->loop}; }
115117
auto operator==(const scheduler&) const -> bool = default;
118+
119+
static constexpr auto query(::beman::execution::get_forward_progress_guarantee_t) noexcept
120+
-> ::beman::execution::forward_progress_guarantee {
121+
return ::beman::execution::forward_progress_guarantee::parallel;
122+
}
116123
};
117124

118125
enum class state : unsigned char { starting, running, finishing };

src/beman/execution/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ target_sources(
8989
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/get_domain_early.hpp
9090
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/get_domain_late.hpp
9191
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/get_env.hpp
92+
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/get_forward_progress_guarantee.hpp
9293
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/get_scheduler.hpp
9394
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/get_stop_token.hpp
9495
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/has_as_awaitable.hpp
@@ -275,6 +276,7 @@ if(BEMAN_USE_MODULES)
275276
get_domain_late.cppm
276277
get_domain.cppm
277278
get_env.cppm
279+
get_forward_progress_guarantee.cppm
278280
get_scheduler.cppm
279281
get_stop_token.cppm
280282
has_as_awaitable.cppm

src/beman/execution/execution.cppm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export import beman.execution.detail.get_completion_signatures; // [exec.getcomp
3131
import beman.execution.detail.get_delegation_scheduler;
3232
import beman.execution.detail.get_domain;
3333
import beman.execution.detail.get_env;
34+
import beman.execution.detail.get_forward_progress_guarantee;
3435
import beman.execution.detail.get_scheduler;
3536
import beman.execution.detail.get_stop_token;
3637
export import beman.execution.detail.inplace_stop_source; // [stopsource.inplace], class inplace_stop_source
@@ -133,14 +134,14 @@ export using ::beman::execution::get_domain_t;
133134
export using ::beman::execution::get_scheduler_t;
134135
export using ::beman::execution::get_delegation_scheduler_t;
135136
export using ::beman::execution::get_await_completion_adaptor_t;
136-
//-dk:TODO export using ::beman::execution::get_forward_progress_guarantee_t;
137+
export using ::beman::execution::get_forward_progress_guarantee_t;
137138

138139
export using ::beman::execution::get_domain;
139140
export using ::beman::execution::get_scheduler;
140141
export using ::beman::execution::get_delegation_scheduler;
141142
export using ::beman::execution::get_await_completion_adaptor;
142-
//-dk:TODO export using ::beman::execution::forward_progress_guarantee;
143-
//-dk:TODO export using ::beman::execution::get_forward_progress_guarantee;
143+
export using ::beman::execution::forward_progress_guarantee;
144+
export using ::beman::execution::get_forward_progress_guarantee;
144145

145146
export using ::beman::execution::get_env_t;
146147
export using ::beman::execution::get_env;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module;
2+
// src/beman/execution/get_forward_progress_guarantee.cppm -*-C++-*-
3+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
#include <beman/execution/detail/get_forward_progress_guarantee.hpp>
6+
7+
export module beman.execution.detail.get_forward_progress_guarantee;
8+
9+
namespace beman::execution {
10+
export using beman::execution::forward_progress_guarantee;
11+
export using beman::execution::get_forward_progress_guarantee_t;
12+
export using beman::execution::get_forward_progress_guarantee;
13+
} // namespace beman::execution

tests/beman/execution/exec-run-loop-general.test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ TEST(exec_run_loop_general) {
2828
});
2929
static_assert(requires { rl.run(); });
3030
static_assert(requires { rl.finish(); });
31+
32+
ASSERT(test_std::get_forward_progress_guarantee(rl.get_scheduler()) ==
33+
test_std::forward_progress_guarantee::parallel);
3134
}

0 commit comments

Comments
 (0)