diff --git a/include/beman/execution/detail/get_forward_progress_guarantee.hpp b/include/beman/execution/detail/get_forward_progress_guarantee.hpp new file mode 100644 index 00000000..bdc0affa --- /dev/null +++ b/include/beman/execution/detail/get_forward_progress_guarantee.hpp @@ -0,0 +1,49 @@ +// include/beman/execution/detail/get_forward_progress_guarantee.hpp -*-C++-*- +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_GET_FORWARD_PROGRESS_GUARANTEE +#define INCLUDED_BEMAN_EXECUTION_DETAIL_GET_FORWARD_PROGRESS_GUARANTEE + +#include +#include +#ifdef BEMAN_HAS_IMPORT_STD +import std; +#else +#include +#endif +#ifdef BEMAN_HAS_MODULES +import beman.execution.detail.forwarding_query; +#else +#include +#endif + +// ---------------------------------------------------------------------------- + +namespace beman::execution { + +enum class forward_progress_guarantee { concurrent, parallel, weakly_parallel }; + +struct get_forward_progress_guarantee_t { + template + requires requires(const Object& object, const get_forward_progress_guarantee_t& tag) { object.query(tag); } + auto operator()(const Object& object) const noexcept -> forward_progress_guarantee { + static_assert(::std::same_as); + return object.query(*this); + } + + template + auto operator()(const Object&) const noexcept -> forward_progress_guarantee { + return forward_progress_guarantee::weakly_parallel; + } + + static constexpr auto query(const ::beman::execution::forwarding_query_t&) noexcept -> bool { return true; } +}; + +inline constexpr get_forward_progress_guarantee_t get_forward_progress_guarantee{}; +} // namespace beman::execution + +// ---------------------------------------------------------------------------- + +#include + +#endif // INCLUDED_BEMAN_EXECUTION_DETAIL_GET_FORWARD_PROGRESS_GUARANTEE diff --git a/include/beman/execution/detail/run_loop.hpp b/include/beman/execution/detail/run_loop.hpp index bb29d675..bdb9360d 100644 --- a/include/beman/execution/detail/run_loop.hpp +++ b/include/beman/execution/detail/run_loop.hpp @@ -19,6 +19,7 @@ import beman.execution.detail.completion_signatures; import beman.execution.detail.env; import beman.execution.detail.get_completion_scheduler; import beman.execution.detail.get_env; +import beman.execution.detail.get_forward_progress_guarantee; import beman.execution.detail.get_stop_token; import beman.execution.detail.immovable; import beman.execution.detail.operation_state; @@ -32,6 +33,7 @@ import beman.execution.detail.unstoppable_token; #include #include #include +#include #include #include #include @@ -113,6 +115,11 @@ class run_loop { auto schedule() noexcept -> sender { return {this->loop}; } auto operator==(const scheduler&) const -> bool = default; + + static constexpr auto query(::beman::execution::get_forward_progress_guarantee_t) noexcept + -> ::beman::execution::forward_progress_guarantee { + return ::beman::execution::forward_progress_guarantee::parallel; + } }; enum class state : unsigned char { starting, running, finishing }; diff --git a/src/beman/execution/CMakeLists.txt b/src/beman/execution/CMakeLists.txt index cfef78f5..36c68048 100644 --- a/src/beman/execution/CMakeLists.txt +++ b/src/beman/execution/CMakeLists.txt @@ -89,6 +89,7 @@ target_sources( ${PROJECT_SOURCE_DIR}/include/beman/execution/detail/get_domain_early.hpp ${PROJECT_SOURCE_DIR}/include/beman/execution/detail/get_domain_late.hpp ${PROJECT_SOURCE_DIR}/include/beman/execution/detail/get_env.hpp + ${PROJECT_SOURCE_DIR}/include/beman/execution/detail/get_forward_progress_guarantee.hpp ${PROJECT_SOURCE_DIR}/include/beman/execution/detail/get_scheduler.hpp ${PROJECT_SOURCE_DIR}/include/beman/execution/detail/get_stop_token.hpp ${PROJECT_SOURCE_DIR}/include/beman/execution/detail/has_as_awaitable.hpp @@ -275,6 +276,7 @@ if(BEMAN_USE_MODULES) get_domain_late.cppm get_domain.cppm get_env.cppm + get_forward_progress_guarantee.cppm get_scheduler.cppm get_stop_token.cppm has_as_awaitable.cppm diff --git a/src/beman/execution/execution.cppm b/src/beman/execution/execution.cppm index cd2ab544..c4a72dd4 100644 --- a/src/beman/execution/execution.cppm +++ b/src/beman/execution/execution.cppm @@ -31,6 +31,7 @@ export import beman.execution.detail.get_completion_signatures; // [exec.getcomp import beman.execution.detail.get_delegation_scheduler; import beman.execution.detail.get_domain; import beman.execution.detail.get_env; +import beman.execution.detail.get_forward_progress_guarantee; import beman.execution.detail.get_scheduler; import beman.execution.detail.get_stop_token; 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; export using ::beman::execution::get_scheduler_t; export using ::beman::execution::get_delegation_scheduler_t; export using ::beman::execution::get_await_completion_adaptor_t; -//-dk:TODO export using ::beman::execution::get_forward_progress_guarantee_t; +export using ::beman::execution::get_forward_progress_guarantee_t; export using ::beman::execution::get_domain; export using ::beman::execution::get_scheduler; export using ::beman::execution::get_delegation_scheduler; export using ::beman::execution::get_await_completion_adaptor; -//-dk:TODO export using ::beman::execution::forward_progress_guarantee; -//-dk:TODO export using ::beman::execution::get_forward_progress_guarantee; +export using ::beman::execution::forward_progress_guarantee; +export using ::beman::execution::get_forward_progress_guarantee; export using ::beman::execution::get_env_t; export using ::beman::execution::get_env; diff --git a/src/beman/execution/get_forward_progress_guarantee.cppm b/src/beman/execution/get_forward_progress_guarantee.cppm new file mode 100644 index 00000000..37fbe820 --- /dev/null +++ b/src/beman/execution/get_forward_progress_guarantee.cppm @@ -0,0 +1,13 @@ +module; +// src/beman/execution/get_forward_progress_guarantee.cppm -*-C++-*- +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include + +export module beman.execution.detail.get_forward_progress_guarantee; + +namespace beman::execution { +export using beman::execution::forward_progress_guarantee; +export using beman::execution::get_forward_progress_guarantee_t; +export using beman::execution::get_forward_progress_guarantee; +} // namespace beman::execution diff --git a/tests/beman/execution/exec-run-loop-general.test.cpp b/tests/beman/execution/exec-run-loop-general.test.cpp index 7e26cb5f..b24bae9a 100644 --- a/tests/beman/execution/exec-run-loop-general.test.cpp +++ b/tests/beman/execution/exec-run-loop-general.test.cpp @@ -28,4 +28,7 @@ TEST(exec_run_loop_general) { }); static_assert(requires { rl.run(); }); static_assert(requires { rl.finish(); }); + + ASSERT(test_std::get_forward_progress_guarantee(rl.get_scheduler()) == + test_std::forward_progress_guarantee::parallel); }