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
40 changes: 11 additions & 29 deletions bench/beman/awaitable_sender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <boost/capy/detail/await_suspend_helper.hpp>
#include <boost/capy/ex/await_context.hpp>
#include <boost/capy/ex/executor_ref.hpp>
#include <boost/capy/ex/root_promise_base.hpp>
#include <boost/capy/results.hpp>

#include <beman/execution/execution.hpp>
Expand Down Expand Up @@ -100,13 +101,6 @@ template<class T>
constexpr bool is_compound_ec_result_v =
is_compound_ec_result<T>::value;

struct frame_cb
{
void (*resume)(frame_cb*);
void (*destroy)(frame_cb*);
void* data;
};

} // namespace detail

/** Sender that wraps a ContextAwaitable.
Expand Down Expand Up @@ -163,6 +157,7 @@ struct awaitable_sender

template<class Receiver>
struct op_state
: root_work_base<op_state<Receiver>>
{
using operation_state_concept =
beman::execution::operation_state_t;
Expand All @@ -176,14 +171,11 @@ struct awaitable_sender
CtxAw aw_;
Receiver rcvr_;
executor_type ex_;
await_context env_;
detail::frame_cb cb_;

op_state(CtxAw aw, Receiver rcvr)
: aw_(std::move(aw))
, rcvr_(std::move(rcvr))
, ex_{}
, cb_{}
{
}

Expand All @@ -192,15 +184,12 @@ struct awaitable_sender
op_state& operator=(op_state const&) = delete;
op_state& operator=(op_state&&) = delete;

static void
on_resume(detail::frame_cb* p) noexcept
void on_resume() noexcept
{
auto* self = static_cast<op_state*>(p->data);
self->complete();
complete();
}

static void
on_destroy(detail::frame_cb*) noexcept
void on_abandon() noexcept
{
}

Expand All @@ -211,7 +200,7 @@ struct awaitable_sender
if constexpr (std::is_void_v<result_type>)
{
aw_.await_resume();
if(env_.stop_token.stop_requested())
if(this->env_.stop_token.stop_requested())
beman::execution::set_stopped(
std::move(rcvr_));
else
Expand All @@ -222,7 +211,7 @@ struct awaitable_sender
detail::is_compound_ec_result_v<result_type>)
{
auto result = aw_.await_resume();
if(env_.stop_token.stop_requested())
if(this->env_.stop_token.stop_requested())
{
beman::execution::set_stopped(
std::move(rcvr_));
Expand All @@ -243,7 +232,7 @@ struct awaitable_sender
detail::is_ec_outcome_v<result_type>)
{
auto result = aw_.await_resume();
if(env_.stop_token.stop_requested())
if(this->env_.stop_token.stop_requested())
{
beman::execution::set_stopped(
std::move(rcvr_));
Expand All @@ -267,7 +256,7 @@ struct awaitable_sender
else
{
auto result = aw_.await_resume();
if(env_.stop_token.stop_requested())
if(this->env_.stop_token.stop_requested())
beman::execution::set_stopped(
std::move(rcvr_));
else
Expand Down Expand Up @@ -299,23 +288,16 @@ struct awaitable_sender
beman::execution::get_stop_token_t{});
}

env_ = await_context{ex_, st, nullptr};
auto h = this->bind_chain(ex_, st);

if(aw_.await_ready())
{
complete();
return;
}

cb_.resume = &on_resume;
cb_.destroy = &on_destroy;
cb_.data = this;

auto h = std::coroutine_handle<>::from_address(
static_cast<void*>(&cb_));

auto resumed = detail::call_await_suspend(
&aw_, h, &env_);
&aw_, h, &this->env_);
if(resumed == h)
complete();
}
Expand Down
7 changes: 2 additions & 5 deletions bench/beman/ctxaw_read_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <boost/capy/buffers.hpp>
#include <boost/capy/concept/read_stream.hpp>
#include <boost/capy/continuation.hpp>
#include <boost/capy/coro_chain.hpp>
#include <boost/capy/ex/await_context.hpp>
#include <boost/capy/results.hpp>
#include <coroutine>
Expand All @@ -27,17 +27,14 @@ struct ctxaw_read_stream
{
struct read_awaitable
{
boost::capy::continuation cont_{};

bool await_ready() const noexcept { return false; }

std::coroutine_handle<>
await_suspend(
std::coroutine_handle<> h,
boost::capy::await_context const* env)
{
cont_.h = h;
env->executor.post(cont_);
env->executor.post(env->park(h));
return std::noop_coroutine();
}

Expand Down
12 changes: 6 additions & 6 deletions bench/beman/sender_await_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "sender_thread_pool.hpp"
#include "awaitable_sender.hpp"

#include <boost/capy/continuation.hpp>
#include <boost/capy/coro_chain.hpp>
#include <boost/capy/ex/execution_context.hpp>

#include <beman/execution/execution.hpp>
Expand Down Expand Up @@ -53,16 +53,16 @@ struct sender_as_capy_executor
pool_->on_work_finished();
}

void post(boost::capy::continuation& c) const;
void post(boost::capy::coro_chain&& c) const;

// Return the handle for symmetric transfer so the
// caller resumes the coroutine inline. Posting would
// cause a lifetime issue since run_async expects to
// hand off ownership via symmetric transfer.
std::coroutine_handle<>
dispatch(boost::capy::continuation& c) const
dispatch(boost::capy::coro_chain&& c) const
{
return c.h;
return c.release_handle();
}

bool operator==(
Expand Down Expand Up @@ -201,10 +201,10 @@ struct scheduled_resume
};

inline void sender_as_capy_executor::post(
boost::capy::continuation& c) const
boost::capy::coro_chain&& c) const
{
auto* p = new scheduled_resume(
pool_scheduler{pool_}, c.h);
pool_scheduler{pool_}, c.release_handle());
ex::start(p->op_);
}

Expand Down
8 changes: 4 additions & 4 deletions bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ class bench_io_context::executor_type
{
}

std::coroutine_handle<> dispatch(continuation& c) const
std::coroutine_handle<> dispatch(coro_chain&& c) const
{
return c.h;
return c.release_handle();
}

void post(continuation& c) const
void post(coro_chain&& c) const
{
c.h.resume();
c.resume();
}

void defer(std::coroutine_handle<> h) const
Expand Down
40 changes: 11 additions & 29 deletions bench/stdexec/awaitable_sender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <boost/capy/detail/await_suspend_helper.hpp>
#include <boost/capy/ex/await_context.hpp>
#include <boost/capy/ex/executor_ref.hpp>
#include <boost/capy/ex/root_promise_base.hpp>
#include <boost/capy/results.hpp>

#include <stdexec/execution.hpp>
Expand Down Expand Up @@ -99,13 +100,6 @@ template<class T>
constexpr bool is_compound_ec_result_v =
is_compound_ec_result<T>::value;

struct frame_cb
{
void (*resume)(frame_cb*);
void (*destroy)(frame_cb*);
void* data;
};

// Return the concrete executor by value, trying get_io_executor
// on the env first, then falling back to the start scheduler.
template<class Env>
Expand Down Expand Up @@ -174,6 +168,7 @@ struct awaitable_sender

template<class Receiver>
struct op_state
: root_work_base<op_state<Receiver>>
{
using operation_state_concept =
stdexec::operation_state_tag;
Expand All @@ -190,14 +185,11 @@ struct awaitable_sender
CtxAw aw_;
Receiver rcvr_;
executor_type ex_;
await_context env_;
detail::frame_cb cb_;

op_state(CtxAw aw, Receiver rcvr)
: aw_(std::move(aw))
, rcvr_(std::move(rcvr))
, ex_{}
, cb_{}
{
}

Expand All @@ -206,15 +198,12 @@ struct awaitable_sender
op_state& operator=(op_state const&) = delete;
op_state& operator=(op_state&&) = delete;

static void
on_resume(detail::frame_cb* p) noexcept
void on_resume() noexcept
{
auto* self = static_cast<op_state*>(p->data);
self->complete();
complete();
}

static void
on_destroy(detail::frame_cb*) noexcept
void on_abandon() noexcept
{
}

Expand All @@ -225,7 +214,7 @@ struct awaitable_sender
if constexpr (std::is_void_v<result_type>)
{
aw_.await_resume();
if(env_.stop_token.stop_requested())
if(this->env_.stop_token.stop_requested())
stdexec::set_stopped(
std::move(rcvr_));
else
Expand All @@ -236,7 +225,7 @@ struct awaitable_sender
detail::is_compound_ec_result_v<result_type>)
{
auto result = aw_.await_resume();
if(env_.stop_token.stop_requested())
if(this->env_.stop_token.stop_requested())
{
stdexec::set_stopped(
std::move(rcvr_));
Expand All @@ -257,7 +246,7 @@ struct awaitable_sender
detail::is_ec_outcome_v<result_type>)
{
auto result = aw_.await_resume();
if(env_.stop_token.stop_requested())
if(this->env_.stop_token.stop_requested())
{
stdexec::set_stopped(
std::move(rcvr_));
Expand All @@ -281,7 +270,7 @@ struct awaitable_sender
else
{
auto result = aw_.await_resume();
if(env_.stop_token.stop_requested())
if(this->env_.stop_token.stop_requested())
stdexec::set_stopped(
std::move(rcvr_));
else
Expand Down Expand Up @@ -312,23 +301,16 @@ struct awaitable_sender
stdexec::get_stop_token_t{});
}

env_ = await_context{ex_, st, nullptr};
auto h = this->bind_chain(ex_, st);

if(aw_.await_ready())
{
complete();
return;
}

cb_.resume = &on_resume;
cb_.destroy = &on_destroy;
cb_.data = this;

auto h = std::coroutine_handle<>::from_address(
static_cast<void*>(&cb_));

auto resumed = detail::call_await_suspend(
&aw_, h, &env_);
&aw_, h, &this->env_);
if(resumed == h)
complete();
}
Expand Down
7 changes: 2 additions & 5 deletions bench/stdexec/ctxaw_read_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <boost/capy/buffers.hpp>
#include <boost/capy/concept/read_stream.hpp>
#include <boost/capy/continuation.hpp>
#include <boost/capy/coro_chain.hpp>
#include <boost/capy/ex/await_context.hpp>
#include <boost/capy/results.hpp>
#include <coroutine>
Expand All @@ -27,17 +27,14 @@ struct ctxaw_read_stream
{
struct read_awaitable
{
boost::capy::continuation cont_{};

bool await_ready() const noexcept { return false; }

std::coroutine_handle<>
await_suspend(
std::coroutine_handle<> h,
boost::capy::await_context const* env)
{
cont_.h = h;
env->executor.post(cont_);
env->executor.post(env->park(h));
return std::noop_coroutine();
}

Expand Down
Loading
Loading