Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 <beman/execution/detail/common.hpp>
#include <beman/execution/detail/suppress_push.hpp>
#ifdef BEMAN_HAS_IMPORT_STD
import std;
#else
#include <concepts>
#endif
#ifdef BEMAN_HAS_MODULES
import beman.execution.detail.forwarding_query;
#else
#include <beman/execution/detail/forwarding_query.hpp>
#endif

// ----------------------------------------------------------------------------

namespace beman::execution {

enum class forward_progress_guarantee { concurrent, parallel, weakly_parallel };

struct get_forward_progress_guarantee_t {
template <typename Object>
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<decltype(object.query(*this)), forward_progress_guarantee>);
return object.query(*this);
}

template <typename Object>
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 <beman/execution/detail/suppress_pop.hpp>

#endif // INCLUDED_BEMAN_EXECUTION_DETAIL_GET_FORWARD_PROGRESS_GUARANTEE
7 changes: 7 additions & 0 deletions include/beman/execution/detail/run_loop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +33,7 @@ import beman.execution.detail.unstoppable_token;
#include <beman/execution/detail/completion_signatures.hpp>
#include <beman/execution/detail/get_completion_scheduler.hpp>
#include <beman/execution/detail/get_env.hpp>
#include <beman/execution/detail/get_forward_progress_guarantee.hpp>
#include <beman/execution/detail/get_stop_token.hpp>
#include <beman/execution/detail/immovable.hpp>
#include <beman/execution/detail/operation_state.hpp>
Expand Down Expand Up @@ -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 };
Expand Down
74 changes: 74 additions & 0 deletions include/beman/execution/detail/sync_wait_with_variant.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// include/beman/execution/detail/sync_wait_with_variant.hpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_SYNC_WAIT_WITH_VARIANT
#define INCLUDED_BEMAN_EXECUTION_DETAIL_SYNC_WAIT_WITH_VARIANT

#include <beman/execution/detail/common.hpp>
#include <beman/execution/detail/suppress_push.hpp>
#ifdef BEMAN_HAS_IMPORT_STD
import std;
#else
#include <optional>
#include <utility>
#endif
#ifdef BEMAN_HAS_MODULES
import beman.execution.detail.apply_sender;
import beman.execution.detail.callable;
import beman.execution.detail.call_result_t;
import beman.execution.detail.get_domain_early;
import beman.execution.detail.into_variant;
import beman.execution.detail.sender_in;
import beman.execution.detail.sync_wait;
import beman.execution.detail.value_types_of_t;
#else
#include <beman/execution/detail/apply_sender.hpp>
#include <beman/execution/detail/callable.hpp>
#include <beman/execution/detail/call_result_t.hpp>
#include <beman/execution/detail/get_domain_early.hpp>
#include <beman/execution/detail/into_variant.hpp>
#include <beman/execution/detail/sender_in.hpp>
#include <beman/execution/detail/sync_wait.hpp>
#include <beman/execution/detail/value_types_of_t.hpp>
#endif

// ----------------------------------------------------------------------------

namespace beman::execution::detail {
template <::beman::execution::sender_in<::beman::execution::detail::sync_wait_env> Sndr>
using sync_wait_with_variant_result_type =
::std::optional<::beman::execution::value_types_of_t<Sndr, ::beman::execution::detail::sync_wait_env>>;
} // namespace beman::execution::detail

namespace beman::execution {

struct sync_wait_with_variant_t {
template <typename Sndr>
requires ::beman::execution::detail::callable<
::beman::execution::sync_wait_t,
::beman::execution::detail::call_result_t<::beman::execution::into_variant_t, Sndr>>
auto apply_sender(Sndr&& sndr) const {
using result_type = ::beman::execution::detail::sync_wait_with_variant_result_type<Sndr>;
if (auto opt_value =
::beman::execution::sync_wait(::beman::execution::into_variant(::std::forward<Sndr>(sndr)))) {
return result_type(::std::move(::std::get<0>(*opt_value)));
}
return result_type(::std::nullopt);
}

template <typename Sndr>
requires requires { typename ::beman::execution::detail::sync_wait_with_variant_result_type<Sndr>; }
auto operator()(Sndr&& sndr) const {
return ::beman::execution::apply_sender(
::beman::execution::detail::get_domain_early(sndr), *this, ::std::forward<Sndr>(sndr));
}
};

inline constexpr sync_wait_with_variant_t sync_wait_with_variant{};
} // namespace beman::execution

// ----------------------------------------------------------------------------

#include <beman/execution/detail/suppress_pop.hpp>

#endif // INCLUDED_BEMAN_EXECUTION_DETAIL_SYNC_WAIT_WITH_VARIANT
10 changes: 10 additions & 0 deletions include/beman/execution/execution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import beman.execution.detail.counting_scope;
import beman.execution.detail.env;
import beman.execution.detail.forwarding_query;
import beman.execution.detail.get_allocator;
import beman.execution.detail.get_await_completion_adaptor;
import beman.execution.detail.get_completion_scheduler;
import beman.execution.detail.get_completion_signatures;
import beman.execution.detail.get_delegation_scheduler;
import beman.execution.detail.get_domain;
import beman.execution.detail.get_forward_progress_guarantee;
import beman.execution.detail.get_env;
import beman.execution.detail.get_scheduler;
import beman.execution.detail.get_stop_token;
Expand Down Expand Up @@ -52,7 +54,10 @@ import beman.execution.detail.spawn;
//-dk:TODO? import beman.execution.detail.split;
import beman.execution.detail.start;
import beman.execution.detail.starts_on;
import beman.execution.detail.stopped_as_error;
import beman.execution.detail.stopped_as_optional;
import beman.execution.detail.sync_wait;
import beman.execution.detail.sync_wait_with_variant;
import beman.execution.detail.then;
import beman.execution.detail.valid_completion_for;
import beman.execution.detail.valid_completion_signatures;
Expand All @@ -73,10 +78,12 @@ import beman.execution.detail.write_env;
#include <beman/execution/detail/env.hpp>
#include <beman/execution/detail/forwarding_query.hpp>
#include <beman/execution/detail/get_allocator.hpp>
#include <beman/execution/detail/get_await_completion_adaptor.hpp>
#include <beman/execution/detail/get_completion_scheduler.hpp>
#include <beman/execution/detail/get_completion_signatures.hpp>
#include <beman/execution/detail/get_delegation_scheduler.hpp>
#include <beman/execution/detail/get_domain.hpp>
#include <beman/execution/detail/get_forward_progress_guarantee.hpp>
#include <beman/execution/detail/get_env.hpp>
#include <beman/execution/detail/get_scheduler.hpp>
#include <beman/execution/detail/get_stop_token.hpp>
Expand Down Expand Up @@ -105,7 +112,10 @@ import beman.execution.detail.write_env;
//-dk:TODO? #include <beman/execution/detail/split.hpp>
#include <beman/execution/detail/start.hpp>
#include <beman/execution/detail/starts_on.hpp>
#include <beman/execution/detail/stopped_as_error.hpp>
#include <beman/execution/detail/stopped_as_optional.hpp>
#include <beman/execution/detail/sync_wait.hpp>
#include <beman/execution/detail/sync_wait_with_variant.hpp>
#include <beman/execution/detail/then.hpp>
#include <beman/execution/detail/valid_completion_for.hpp>
#include <beman/execution/detail/valid_completion_signatures.hpp>
Expand Down
4 changes: 4 additions & 0 deletions src/beman/execution/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -181,6 +182,7 @@ target_sources(
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/suppress_push.hpp
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/suspend_complete.hpp
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/sync_wait.hpp
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/sync_wait_with_variant.hpp
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/tag_of_t.hpp
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/then.hpp
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/transform_sender.hpp
Expand Down Expand Up @@ -275,6 +277,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
Expand Down Expand Up @@ -367,6 +370,7 @@ if(BEMAN_USE_MODULES)
stopped_as_optional.cppm
suspend_complete.cppm
sync_wait.cppm
sync_wait_with_variant.cppm
tag_of_t.cppm
then.cppm
transform_sender.cppm
Expand Down
12 changes: 7 additions & 5 deletions src/beman/execution/execution.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,6 +69,7 @@ import beman.execution.detail.stoppable_source;
import beman.execution.detail.stopped_as_error;
import beman.execution.detail.stopped_as_optional;
import beman.execution.detail.sync_wait;
import beman.execution.detail.sync_wait_with_variant;
export import beman.execution.detail.tag_of_t; // [exec.getcomplsigs], completion signatures
import beman.execution.detail.then;
import beman.execution.detail.transform_sender;
Expand Down Expand Up @@ -133,14 +135,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;
Expand Down Expand Up @@ -231,10 +233,10 @@ export using ::beman::execution::run_loop;

// [exec.consumers], consumers
export using ::beman::execution::sync_wait_t;
//-dk:TODO export using ::beman::execution::sync_wait_with_variant_t;
export using ::beman::execution::sync_wait_with_variant_t;

export using ::beman::execution::sync_wait;
//-dk:TODO export using ::beman::execution::sync_wait_with_variant;
export using ::beman::execution::sync_wait_with_variant;

// [exec.as.awaitable]
export using ::beman::execution::as_awaitable_t;
Expand Down
13 changes: 13 additions & 0 deletions src/beman/execution/get_forward_progress_guarantee.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module;
// src/beman/execution/get_forward_progress_guarantee.cppm -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/execution/detail/get_forward_progress_guarantee.hpp>

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
12 changes: 12 additions & 0 deletions src/beman/execution/sync_wait_with_variant.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module;
// src/beman/execution/sync_wait_with_variant.cppm -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/execution/detail/sync_wait_with_variant.hpp>

export module beman.execution.detail.sync_wait_with_variant;

namespace beman::execution {
export using beman::execution::sync_wait_with_variant_t;
export using beman::execution::sync_wait_with_variant;
} // namespace beman::execution
1 change: 1 addition & 0 deletions tests/beman/execution/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ list(
exec-stopped-as-error.test
exec-stopped-as-optional.test
exec-sync-wait.test
exec-sync-wait-with-variant.test
exec-then.test
exec-utils-cmplsigs.test
exec-when-all.test
Expand Down
3 changes: 3 additions & 0 deletions tests/beman/execution/exec-run-loop-general.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading
Loading