Skip to content

Commit

Permalink
fix: Use execution::(un)stoppable_token concepts to fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Tradias committed Dec 11, 2023
1 parent b45f41b commit 7cb4f8e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
7 changes: 4 additions & 3 deletions src/agrpc/detail/asio_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef AGRPC_DETAIL_ASIO_UTILS_HPP
#define AGRPC_DETAIL_ASIO_UTILS_HPP

#include <agrpc/detail/asio_forward.hpp>
#include <agrpc/detail/config.hpp>
#include <agrpc/detail/execution.hpp>

Expand Down Expand Up @@ -91,7 +92,7 @@ void complete_immediately(CompletionHandler&& completion_handler, Function&& fun
#endif
}

struct UncancellableToken
struct UncancellableSlot
{
static constexpr bool is_connected() noexcept { return false; }
};
Expand All @@ -100,9 +101,9 @@ template <class Object>
auto get_cancellation_slot([[maybe_unused]] const Object& object) noexcept
{
#ifdef AGRPC_ASIO_HAS_CANCELLATION_SLOT
return asio::get_associated_cancellation_slot(object, UncancellableToken{});
return asio::get_associated_cancellation_slot(object, UncancellableSlot{});
#else
return UncancellableToken{};
return UncancellableSlot{};
#endif
}

Expand Down
16 changes: 3 additions & 13 deletions src/agrpc/detail/association_asio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,14 @@ AGRPC_NAMESPACE_BEGIN()

namespace detail
{
template <class CancellationSlot, class = void>
inline constexpr bool IS_CANCELLATION_SLOT = true;

template <class CancellationSlot>
inline constexpr bool
IS_CANCELLATION_SLOT<CancellationSlot, decltype((void)std::declval<CancellationSlot>().stop_requested())> = false;

template <class T, class = std::false_type>
inline constexpr bool IS_STOP_EVER_POSSIBLE_V = IS_CANCELLATION_SLOT<T>;

template <class T>
using IsStopEverPossibleHelper = std::bool_constant<(T{}.stop_possible())>;
inline constexpr bool IS_CANCELLATION_SLOT = !exec::stoppable_token<CancellationSlot>;

template <class T>
inline constexpr bool IS_STOP_EVER_POSSIBLE_V<T, detail::IsStopEverPossibleHelper<T>> = false;
inline constexpr bool IS_STOP_EVER_POSSIBLE_V = !exec::unstoppable_token<T>;

template <>
inline constexpr bool IS_STOP_EVER_POSSIBLE_V<UncancellableToken> = false;
inline constexpr bool IS_STOP_EVER_POSSIBLE_V<UncancellableSlot> = false;

template <class T>
inline constexpr bool IS_EXECUTOR = asio::is_executor<T>::value || asio::execution::is_executor_v<T>;
Expand Down
8 changes: 1 addition & 7 deletions src/agrpc/detail/association_execution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,8 @@ namespace detail
template <class CancellationSlot>
inline constexpr bool IS_CANCELLATION_SLOT = false;

template <class T, class = std::false_type>
inline constexpr bool IS_STOP_EVER_POSSIBLE_V = true;

template <class T>
using IsStopEverPossibleHelper = std::bool_constant<(T{}.stop_possible())>;

template <class T>
inline constexpr bool IS_STOP_EVER_POSSIBLE_V<T, detail::IsStopEverPossibleHelper<T>> = false;
inline constexpr bool IS_STOP_EVER_POSSIBLE_V = !exec::unstoppable_token<T>;

template <class T>
inline constexpr bool IS_EXECUTOR = exec::scheduler<T>;
Expand Down
15 changes: 15 additions & 0 deletions src/agrpc/detail/execution_asio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ constexpr UnstoppableToken get_stop_token(const Receiver&) noexcept
template <class>
using stop_token_type_t = UnstoppableToken;

template <class T, class = void>
inline constexpr bool stoppable_token = false;

template <class T>
inline constexpr bool stoppable_token<T, decltype((void)std::declval<T>().stop_possible())> = true;

template <class T, class = std::false_type>
inline constexpr bool unstoppable_token = false;

template <class T>
using UnstoppableTokenHelper = std::bool_constant<(T{}.stop_possible())>;

template <class T>
inline constexpr bool unstoppable_token<T, exec::UnstoppableTokenHelper<T>> = true;

namespace detail
{
template <class T>
Expand Down
3 changes: 3 additions & 0 deletions src/agrpc/detail/execution_stdexec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ using ::stdexec::start;
template <class Receiver>
using stop_token_type_t = ::stdexec::stop_token_of_t<::stdexec::env_of_t<Receiver>>;

using ::stdexec::stoppable_token;
using ::stdexec::unstoppable_token;

using ::stdexec::tag_t;
} // namespace exec

Expand Down
16 changes: 16 additions & 0 deletions src/agrpc/detail/execution_unifex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ using ::unifex::set_error;
using ::unifex::set_value;
using ::unifex::start;
using ::unifex::stop_token_type_t;

template <class T, class = void>
inline constexpr bool stoppable_token = false;

template <class T>
inline constexpr bool stoppable_token<T, decltype((void)std::declval<T>().stop_possible())> = true;

template <class T, class = std::false_type>
inline constexpr bool unstoppable_token = false;

template <class T>
using UnstoppableTokenHelper = std::bool_constant<(T{}.stop_possible())>;

template <class T>
inline constexpr bool unstoppable_token<T, exec::UnstoppableTokenHelper<T>> = true;

using ::unifex::tag_t;
} // namespace exec

Expand Down

0 comments on commit 7cb4f8e

Please sign in to comment.