Skip to content

Commit

Permalink
Name change: cinfo --> coro_data
Browse files Browse the repository at this point in the history
  • Loading branch information
jnbrq committed Oct 1, 2023
1 parent 03252d7 commit b877bd6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 51 deletions.
4 changes: 2 additions & 2 deletions examples/await_transform_extender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace core {
template <>
struct await_transform_extender<_get_env_tag> {
auto await_transform(
auto cinfo,
auto coro_data,
[[maybe_unused]] util::source_location const loc = util::source_location::current()) const noexcept {
return immediately_return{cinfo->env()};
return immediately_return{coro_data->env()};
}
};

Expand Down
16 changes: 8 additions & 8 deletions include/cxxdes/core/impl/await_transform.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ struct await_ops_mixin {
util::source_location const loc = util::source_location::current()) {
auto result = awaitable_wrapper<std::remove_cvref_t<A>>{
std::forward<A>(a),
derived().cinfo.get(),
derived().cinfo->env()->current_coroutine()
derived().coro_data.get(),
derived().coro_data->env()->current_coroutine()
};
derived().cinfo->env()->loc_ = loc;
derived().coro_data->env()->loc_ = loc;
result.a.await_bind(
derived().cinfo->env(),
derived().cinfo->priority());
derived().coro_data->env(),
derived().coro_data->priority());
return result;
}

Expand All @@ -53,15 +53,15 @@ struct await_ops_mixin {
auto await_transform(
await_transform_extender<T> const &a,
util::source_location const loc = util::source_location::current()) {
return a.await_transform(derived().cinfo, loc);
return a.await_transform(derived().coro_data, loc);
}

auto await_transform(this_coroutine) noexcept {
return immediately_return{derived().cinfo};
return immediately_return{derived().coro_data};
}

auto await_transform(this_environment) noexcept {
return immediately_return{derived().cinfo->env()};
return immediately_return{derived().coro_data->env()};
}

template <awaitable A>
Expand Down
66 changes: 33 additions & 33 deletions include/cxxdes/core/impl/coroutine.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ template <typename Derived, typename ReturnValue>
struct coroutine_return_value_mixin {
[[nodiscard]]
ReturnValue const &return_value() const noexcept {
return static_cast<Derived const *>(this)->cinfo()->return_value();
return static_cast<Derived const *>(this)->coro_data()->return_value();
}
};

Expand All @@ -20,8 +20,8 @@ struct coroutine:
using coroutine_data_type = coroutine_data_<ReturnType, Unique>;

explicit
coroutine(memory::ptr<coroutine_data_type> cinfo = nullptr):
cinfo_{std::move(cinfo)} {
coroutine(memory::ptr<coroutine_data_type> coro_data = nullptr):
coro_data_{std::move(coro_data)} {
}

coroutine(coroutine const &other) requires (not Unique) {
Expand All @@ -30,7 +30,7 @@ struct coroutine:

coroutine &operator=(coroutine const &other) requires (not Unique) {
if (this != &other) {
cinfo_ = other.cinfo_;
coro_data_ = other.coro_data_;
completion_token_ = nullptr;
return_ = other.return_;
}
Expand All @@ -46,73 +46,73 @@ struct coroutine:

coroutine &operator=(coroutine &&other) {
if (this != &other) {
cinfo_ = std::move(other.cinfo_);
coro_data_ = std::move(other.coro_data_);
std::swap(completion_token_, other.completion_token_);
std::swap(return_, other.return_);
}
return *this;
}

~coroutine() {
if (cinfo_) cinfo_->destroy_if_not_started_();
if (coro_data_) coro_data_->destroy_if_not_started_();
}

[[nodiscard]]
bool valid() const noexcept {
return cinfo_;
return coro_data_;
}

[[nodiscard]]
operator bool() const noexcept {
return valid();
}

coroutine_data_type const *cinfo() const noexcept {
return cinfo_.get();
coroutine_data_type const *coro_data() const noexcept {
return coro_data_.get();
}

[[nodiscard]]
bool complete() const noexcept {
return cinfo_->complete();
return coro_data_->complete();
}

template <typename T = interrupted_exception>
void interrupt(T &&t = interrupted_exception{}) noexcept {
cinfo_->interrupt(std::forward<T>(t));
coro_data_->interrupt(std::forward<T>(t));
}

[[nodiscard]]
bool interrupted() const noexcept {
return cinfo_->interrupted();
return coro_data_->interrupted();
}

[[nodiscard]]
priority_type priority() const noexcept {
return cinfo_->priority();
return coro_data_->priority();
}

auto &priority(priority_type priority) & noexcept {
cinfo_->priority(priority);
coro_data_->priority(priority);
return *this;
}

auto &&priority(priority_type priority) && noexcept {
cinfo_->priority(priority);
coro_data_->priority(priority);
return std::move(*this);
}

[[nodiscard]]
time_integral latency() const noexcept {
return cinfo_->latency();
return coro_data_->latency();
}

auto &latency(time_integral latency) & noexcept {
cinfo_->latency(latency);
coro_data_->latency(latency);
return *this;
}

auto &&latency(time_integral latency) && noexcept {
cinfo_->latency(latency);
coro_data_->latency(latency);
return std::move(*this);
}

Expand Down Expand Up @@ -147,11 +147,11 @@ struct coroutine:
}

void await_bind(environment *env, priority_type priority = 0) {
cinfo_->bind_(env, priority);
coro_data_->bind_(env, priority);
}

bool await_ready() const noexcept {
return cinfo_->complete();
return coro_data_->complete();
}

void await_suspend(coroutine_data_ptr phandle) {
Expand All @@ -160,8 +160,8 @@ struct coroutine:

completion_token_ = new token{return_.latency, return_.priority, phandle};
if (completion_token_->priority == priority_consts::inherit)
completion_token_->priority = cinfo_->priority_;
cinfo_->completion_token(completion_token_);
completion_token_->priority = coro_data_->priority_;
coro_data_->completion_token(completion_token_);
}

token *await_token() const noexcept {
Expand All @@ -174,10 +174,10 @@ struct coroutine:
if constexpr (std::is_same_v<ReturnType, void>)
return ;
else {
if (!cinfo_->has_return_value())
if (!coro_data_->has_return_value())
throw std::runtime_error("no return value from the coroutine<T> [T != void]!");

return cinfo_->return_value();
return coro_data_->return_value();
}
}

Expand All @@ -187,10 +187,10 @@ struct coroutine:
if constexpr (std::is_same_v<ReturnType, void>)
return ;
else {
if (!cinfo_->has_return_value())
if (!coro_data_->has_return_value())
throw std::runtime_error("no return value from the coroutine<T> [T != void]!");

return std::move(cinfo_->return_value());
return std::move(coro_data_->return_value());
}
}

Expand All @@ -199,7 +199,7 @@ struct coroutine:
}

private:
memory::ptr<coroutine_data_type> cinfo_ = nullptr;
memory::ptr<coroutine_data_type> coro_data_ = nullptr;
token *completion_token_ = nullptr; // must be non-owning, in case of copies

struct {
Expand Down Expand Up @@ -232,18 +232,18 @@ public:
return_void_mixin<promise_type>,
return_value_mixin<promise_type>
>, detail::await_ops_mixin<promise_type> {
memory::ptr<coroutine_data_type> cinfo;
memory::ptr<coroutine_data_type> coro_data;

template <typename ...Args>
promise_type(Args && ...args) {
auto loc = util::extract_first_type<util::source_location>(args...);
auto coro = std::coroutine_handle<promise_type>::from_promise(*this);
cinfo = new coroutine_data_type(loc);
cinfo->push_coro_(coro);
coro_data = new coroutine_data_type(loc);
coro_data->push_coro_(coro);
}

coroutine get_return_object() {
return coroutine(cinfo);
return coroutine(coro_data);
}

auto initial_suspend() noexcept -> std::suspend_always { return {}; }
Expand All @@ -263,11 +263,11 @@ public:

template <typename T>
void emplace_return_value(T &&t) {
cinfo->emplace_return_value(std::forward<T>(t));
coro_data->emplace_return_value(std::forward<T>(t));
}

void do_return() {
cinfo->do_return();
coro_data->do_return();
}

~promise_type() {
Expand Down
16 changes: 8 additions & 8 deletions include/cxxdes/core/impl/subroutine.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct subroutine {

void await_suspend(std::coroutine_handle<>) {
auto &promise = h_.promise();
promise.cinfo->push_coro_(h_);
promise.coro_data->push_coro_(h_);
}

ReturnType await_resume() {
Expand All @@ -45,9 +45,9 @@ private:
template <typename>
friend struct detail::await_ops_mixin;

void bind_coroutine_(coroutine_data_ptr cinfo) {
void bind_coroutine_(coroutine_data_ptr coro_data) {
auto &promise = h_.promise();
promise.cinfo = std::move(cinfo);
promise.coro_data = std::move(coro_data);
}

template <typename Derived>
Expand Down Expand Up @@ -78,7 +78,7 @@ public:

std::coroutine_handle<promise_type> h = nullptr;
std::exception_ptr eptr = nullptr;
coroutine_data_ptr cinfo = nullptr;
coroutine_data_ptr coro_data = nullptr;

promise_type() {
h = std::coroutine_handle<promise_type>::from_promise(*this);
Expand All @@ -91,15 +91,15 @@ public:
auto initial_suspend() noexcept -> std::suspend_always { return {}; }
auto final_suspend() noexcept {
struct final_awaitable {
coroutine_data_ptr cinfo;
coroutine_data_ptr coro_data;

bool await_ready() noexcept { return false; }
void await_suspend(std::coroutine_handle<>) noexcept {
cinfo->pop_coro_();
coro_data->pop_coro_();
}
void await_resume() noexcept { }
};
return final_awaitable{cinfo};
return final_awaitable{coro_data};
}

auto unhandled_exception() {
Expand All @@ -120,7 +120,7 @@ namespace detail {
template <typename Derived>
template <typename ReturnType>
auto &&await_ops_mixin<Derived>::await_transform(subroutine<ReturnType> &&a) {
a.bind_coroutine_(derived().cinfo.get());
a.bind_coroutine_(derived().coro_data.get());
return std::move(a);
}

Expand Down

0 comments on commit b877bd6

Please sign in to comment.