2
0
mirror of https://github.com/boostorg/cobalt.git synced 2026-01-19 16:12:15 +00:00

removed requirement for executor const refs.

This commit is contained in:
Klemens Morgenstern
2024-10-29 23:44:02 +08:00
parent 2eb10b36f9
commit ebe6848362
5 changed files with 29 additions and 35 deletions

View File

@@ -56,7 +56,7 @@ struct fork
bool outstanding_work() {return use_count != 0u;}
const executor * exec = nullptr;
std::optional<executor> exec = nullptr;
bool wired_up() {return exec != nullptr;}
using executor_type = executor;

View File

@@ -163,7 +163,7 @@ struct gather_variadic_impl
#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
this->loc = loc;
#endif
this->exec = &cobalt::detail::get_executor(h);
this->exec = cobalt::detail::get_executor(h);
last_forked.release().resume();
while (last_index < tuple_size)
impls[last_index++](*this).release();
@@ -362,7 +362,7 @@ struct gather_ranged_impl
#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
this->loc = loc;
#endif
exec = &detail::get_executor(h);
exec = detail::get_executor(h);
last_forked.release().resume();
while (last_index < cancel.size())

View File

@@ -73,6 +73,24 @@ struct completion_handler_noop_executor
};
template<typename Promise>
executor
get_executor(std::coroutine_handle<Promise> h)
{
if constexpr (requires {h.promise().get_executor();})
{
return h.promise().get_executor();
}
else
return this_thread::get_executor();
}
inline executor
get_executor(std::coroutine_handle<>)
{
return this_thread::get_executor();
}
struct completion_handler_base
{
@@ -84,7 +102,7 @@ struct completion_handler_base
}
using executor_type = executor;
const executor_type & executor_ ;
executor_type executor_ ;
const executor_type & get_executor() const noexcept
{
return executor_ ;
@@ -113,11 +131,10 @@ struct completion_handler_base
}
template<typename Promise>
requires (requires (Promise p) {{p.get_executor()} -> std::same_as<const executor&>;})
completion_handler_base(std::coroutine_handle<Promise> h,
completed_immediately_t * completed_immediately = nullptr)
: cancellation_slot(asio::get_associated_cancellation_slot(h.promise())),
executor_(h.promise().get_executor()),
executor_(cobalt::detail::get_executor(h)),
#if !defined(BOOST_COBALT_NO_PMR)
allocator(asio::get_associated_allocator(h.promise(), this_thread::get_allocator())),
#else
@@ -128,24 +145,22 @@ struct completion_handler_base
}
#if !defined(BOOST_COBALT_NO_PMR)
template<typename Promise>
requires (requires (Promise p) {{p.get_executor()} -> std::same_as<const executor&>;})
completion_handler_base(std::coroutine_handle<Promise> h,
pmr::memory_resource * resource,
completed_immediately_t * completed_immediately = nullptr)
: cancellation_slot(asio::get_associated_cancellation_slot(h.promise())),
executor_(h.promise().get_executor()),
executor_(cobalt::detail::get_executor(h)),
allocator(resource),
completed_immediately(completed_immediately)
{
}
#else
template<typename Promise>
requires (requires (Promise p) {{p.get_executor()} -> std::same_as<const executor&>;})
completion_handler_base(std::coroutine_handle<Promise> h,
detail::sbo_resource * resource,
completed_immediately_t * completed_immediately = nullptr)
: cancellation_slot(asio::get_associated_cancellation_slot(h.promise())),
executor_(h.promise().get_executor()),
executor_(cobalt::detail::get_executor(h)),
allocator(resource),
completed_immediately(completed_immediately)
{
@@ -166,27 +181,6 @@ void assign_cancellation(std::coroutine_handle<Promise> h, Handler && func)
h.promise().get_cancellation_slot().assign(std::forward<Handler>(func));
}
template<typename Promise>
const executor &
get_executor(std::coroutine_handle<Promise> h)
{
if constexpr (requires {h.promise().get_executor();})
{
static_assert(std::same_as<decltype(h.promise().get_executor()),
const executor &>,
"for performance reasons, the get_executor function on a promise must return a const reference");
return h.promise().get_executor();
}
else
return this_thread::get_executor();
}
inline const executor &
get_executor(std::coroutine_handle<>)
{
return this_thread::get_executor();
}
}
template<typename ... Args>

View File

@@ -192,7 +192,7 @@ struct join_variadic_impl
#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
this->loc = loc;
#endif
this->exec = &detail::get_executor(h);
this->exec = detail::get_executor(h);
last_forked.release().resume();
while (last_index < tuple_size)
impls[last_index++](*this).release();
@@ -450,7 +450,7 @@ struct join_ranged_impl
#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
this->loc = loc;
#endif
exec = &detail::get_executor(h);
exec = detail::get_executor(h);
last_forked.release().resume();
while (last_index < cancel.size())

View File

@@ -305,7 +305,7 @@ struct race_variadic_impl
{
this->loc = loc;
this->exec = &cobalt::detail::get_executor(h);
this->exec = cobalt::detail::get_executor(h);
last_forked.release().resume();
if (!this->outstanding_work()) // already done, resume rightaway.
@@ -617,7 +617,7 @@ struct race_ranged_impl
const boost::source_location & loc = BOOST_CURRENT_LOCATION)
{
this->loc = loc;
this->exec = &detail::get_executor(h);
this->exec = detail::get_executor(h);
last_forked.release().resume();
if (!this->outstanding_work()) // already done, resume rightaway.