Skip to content

Commit

Permalink
Rename phandle --> coro_data
Browse files Browse the repository at this point in the history
  • Loading branch information
jnbrq committed Oct 1, 2023
1 parent debea51 commit 11a5c7e
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 26 deletions.
4 changes: 2 additions & 2 deletions examples/barebones_awaitable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ struct example {
return false;
}

void await_suspend(coroutine_data_ptr phandle) {
tkn_ = new token(env_->now() + latency_, priority_, phandle);
void await_suspend(coroutine_data_ptr coro_data) {
tkn_ = new token(env_->now() + latency_, priority_, coro_data);

// create a token and do something with it
env_->schedule_token(tkn_); // like, scheduling it
Expand Down
8 changes: 4 additions & 4 deletions include/cxxdes/core/impl/any_of.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct any_all_helper {
// inherit the output_event features
completion_tkn->time += tkn->time;
completion_tkn->priority = tkn->priority;
completion_tkn->phandle = tkn->phandle;
completion_tkn->coro_data = tkn->coro_data;
env->schedule_token(completion_tkn.get());
completion_tkn = nullptr;
}
Expand Down Expand Up @@ -48,8 +48,8 @@ struct any_all_helper {
return Condition::operator()(total, remaining_);
}

void await_suspend(coroutine_data_ptr phandle) {
tkn_ = new token(latency_, priority_, phandle);
void await_suspend(coroutine_data_ptr coro_data) {
tkn_ = new token(latency_, priority_, coro_data);

auto handler = new custom_handler;
handler->total = derived().count();
Expand All @@ -58,7 +58,7 @@ struct any_all_helper {
handler->completion_tkn = tkn_;

derived().apply([&](auto &a) {
a.await_suspend(phandle);
a.await_suspend(coro_data);
if (a.await_token())
a.await_token()->handler = handler;
});
Expand Down
10 changes: 5 additions & 5 deletions include/cxxdes/core/impl/await_transform.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
template <awaitable A>
struct awaitable_wrapper {
A a;
coroutine_data_ptr phandle_this = nullptr;
coroutine_data_ptr phandle_old = nullptr;
coroutine_data_ptr coro_data_this = nullptr;
coroutine_data_ptr coro_data_old = nullptr;

bool await_ready() {
return a.await_ready();
}

void await_suspend(coroutine_handle) {
a.await_suspend(phandle_old);
a.await_suspend(coro_data_old);
}

auto await_resume() {
if (phandle_this->interrupted())
phandle_this->raise_interrupt_();
if (coro_data_this->interrupted())
coro_data_this->raise_interrupt_();
return a.await_resume();
}
};
Expand Down
4 changes: 2 additions & 2 deletions include/cxxdes/core/impl/awaitable.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ concept awaitable = requires(
T t,
environment *env,
priority_type inherited_priority,
coroutine_data_ptr phandle) {
coroutine_data_ptr coro_data) {
{ t.await_bind(env, inherited_priority) };
{ t.await_ready() } -> std::same_as<bool>;
{ t.await_suspend(phandle) };
{ t.await_suspend(coro_data) };
{ t.await_token() } -> std::same_as<token *>;
{ t.await_resume() };
{ t.await_resume(no_return_value_tag {}) } -> std::same_as<void>;
Expand Down
4 changes: 2 additions & 2 deletions include/cxxdes/core/impl/coroutine.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ struct coroutine:
return coro_data_->complete();
}

void await_suspend(coroutine_data_ptr phandle) {
void await_suspend(coroutine_data_ptr coro_data) {
if (completion_token_)
throw std::runtime_error("coroutine<> is already being awaited!");

completion_token_ = new token{return_.latency, return_.priority, phandle};
completion_token_ = new token{return_.latency, return_.priority, coro_data};
if (completion_token_->priority == priority_consts::inherit)
completion_token_->priority = coro_data_->priority_;
coro_data_->completion_token(completion_token_);
Expand Down
6 changes: 3 additions & 3 deletions include/cxxdes/core/impl/environment.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ struct environment {
if (tkn->handler) {
tkn->handler->invoke(tkn);
}
else if (tkn->phandle) {
current_coroutine_ = tkn->phandle;
tkn->phandle->resume();
else if (tkn->coro_data) {
current_coroutine_ = tkn->coro_data;
tkn->coro_data->resume();
current_coroutine_ = nullptr;
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/cxxdes/core/impl/timeout.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct timeout_base {
return env().now() >= derived().time();
}

void await_suspend(coroutine_data_ptr phandle) {
void await_suspend(coroutine_data_ptr coro_data) {
time_integral pt = 0;

if constexpr (Timeout) {
Expand All @@ -28,7 +28,7 @@ struct timeout_base {
pt = derived().time();
}

env_->schedule_token(tkn_ = new token(pt, priority_, phandle));
env_->schedule_token(tkn_ = new token(pt, priority_, coro_data));
}

token *await_token() const noexcept {
Expand Down
9 changes: 6 additions & 3 deletions include/cxxdes/core/impl/token.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ struct token_handler: memory::reference_counted_base<token_handler> {
};

struct token: memory::reference_counted_base<token> {
token(time_integral time, priority_type priority, coroutine_data_ptr phandle):
token(time_integral time, priority_type priority, coroutine_data_ptr coro_data):
time{time},
priority{priority},
phandle{phandle} { }
coro_data{coro_data} { }

// schedule time
time_integral time = 0;
Expand All @@ -16,8 +16,11 @@ struct token: memory::reference_counted_base<token> {
priority_type priority = 0;

// coroutine to continue
coroutine_data_ptr phandle = nullptr;
coroutine_data_ptr coro_data = nullptr;

// token handler can be modified only by all and any compositions
memory::ptr<token_handler> handler = nullptr;

// exception to be propagated
std::exception_ptr exception;
};
6 changes: 3 additions & 3 deletions include/cxxdes/sync/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct wait_awaitable {
}

bool await_ready() const noexcept { return false; }
void await_suspend(coroutine_data_ptr phandle);
void await_suspend(coroutine_data_ptr coro_data);
token *await_token() const noexcept { return tkn_; }
void await_resume(no_return_value_tag = {}) const noexcept { }

Expand Down Expand Up @@ -108,8 +108,8 @@ inline bool wake_awaitable::await_ready() {
return true;
}

inline void wait_awaitable::await_suspend(coroutine_data_ptr phandle) {
tkn_ = new token(latency_, priority_, phandle);
inline void wait_awaitable::await_suspend(coroutine_data_ptr coro_data) {
tkn_ = new token(latency_, priority_, coro_data);
evt_->tokens_.push_back(tkn_);
}

Expand Down

0 comments on commit 11a5c7e

Please sign in to comment.