Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-win workarounds. #136

Closed
wants to merge 1 commit into from
Closed
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
25 changes: 3 additions & 22 deletions include/boost/cobalt/detail/detached.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,11 @@ struct detached_promise

[[nodiscard]] detached get_return_object();

auto await_transform(
std::suspend_never await_transform(
cobalt::this_coro::reset_cancellation_source_t<asio::cancellation_slot> reset) noexcept
{
struct result
{
detached_promise * promise;
asio::cancellation_slot slot;

constexpr bool await_ready() const noexcept
{
return true;
}

void await_suspend(std::coroutine_handle<void>) noexcept
{
}

auto await_resume()
{
promise->reset_cancellation_source(std::move(slot));
}
};

return result{this, std::move(reset.source)};
this->reset_cancellation_source(reset.source);
return {};
}

using executor_type = executor;
Expand Down
79 changes: 40 additions & 39 deletions include/boost/cobalt/detail/fork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,39 +136,40 @@ struct fork
cancellation_slot_type get_cancellation_slot() const { return cancel; }

constexpr static std::suspend_never initial_suspend() noexcept {return {};}
auto final_suspend() noexcept

struct final_awaitable
{
if (cancel.is_connected())
cancel.clear();
struct awaitable
promise_type * self;
bool await_ready() noexcept
{
promise_type * self;
bool await_ready() noexcept
{
return self->state->use_count != 1u;
}
return self->state->use_count != 1u;
}

std::coroutine_handle<void> await_suspend(std::coroutine_handle<promise_type> h) noexcept
{
auto pp = h.promise().state.detach();
std::coroutine_handle<void> await_suspend(std::coroutine_handle<promise_type> h) noexcept
{
auto pp = h.promise().state.detach();

#if defined(BOOST_COBALT_NO_SELF_DELETE)
h.promise().~promise_type();
h.promise().~promise_type();
#else
// mem is in a monotonic_resource, this is fine on msvc- gcc doesn't like it though
h.destroy();
// mem is in a monotonic_resource, this is fine on msvc- gcc doesn't like it though
h.destroy();
#endif
pp->use_count--;
BOOST_ASSERT(pp->use_count == 0u);
if (pp->coro)
return pp->coro.release();
else
return std::noop_coroutine();
}

constexpr static void await_resume() noexcept {}
};
return awaitable{this};
pp->use_count--;
BOOST_ASSERT(pp->use_count == 0u);
if (pp->coro)
return pp->coro.release();
else
return std::noop_coroutine();
}

constexpr static void await_resume() noexcept {}
};
final_awaitable final_suspend() noexcept
{
if (cancel.is_connected())
cancel.clear();
return final_awaitable{this};
}
void return_void()
{
Expand Down Expand Up @@ -204,22 +205,22 @@ struct fork
return wrapped_awaitable{aw};
}

auto await_transform(wired_up_t)
struct wired_up_awaitable
{
struct awaitable
promise_type * promise;
bool await_ready() const noexcept
{
promise_type * promise;
bool await_ready() const noexcept
{
return promise->state->wired_up();
}
void await_suspend(std::coroutine_handle<promise_type>)
{
}
constexpr static void await_resume() noexcept {}
};
return promise->state->wired_up();
}
void await_suspend(std::coroutine_handle<promise_type>)
{
}
constexpr static void await_resume() noexcept {}
};

return awaitable{this};
auto await_transform(wired_up_t)
{
return wired_up_awaitable{this};
}


Expand Down
63 changes: 32 additions & 31 deletions include/boost/cobalt/detail/generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,45 +306,46 @@ struct generator_promise
}

std::suspend_never initial_suspend() {return {};}
auto final_suspend() noexcept

struct final_awaitable
{
struct final_awaitable
generator_promise * generator;
bool await_ready() const noexcept
{
generator_promise * generator;
bool await_ready() const noexcept
{
return generator->receiver && generator->receiver->awaited_from.get() == nullptr;
}

auto await_suspend(std::coroutine_handle<generator_promise> h) noexcept
{
std::coroutine_handle<void> res = std::noop_coroutine();
if (generator->receiver && generator->receiver->awaited_from.get() != nullptr)
res = generator->receiver->awaited_from.release();
if (generator->receiver)
generator->receiver->done = true;

return generator->receiver && generator->receiver->awaited_from.get() == nullptr;
}

if (auto & rec = h.promise().receiver; rec != nullptr)
{
if (!rec->done && !rec->exception)
rec->exception = detail::completed_unexpected();
rec->done = true;
rec->awaited_from.reset(nullptr);
rec = nullptr;
}
auto await_suspend(std::coroutine_handle<generator_promise> h) noexcept
{
std::coroutine_handle<void> res = std::noop_coroutine();
if (generator->receiver && generator->receiver->awaited_from.get() != nullptr)
res = generator->receiver->awaited_from.release();
if (generator->receiver)
generator->receiver->done = true;

detail::self_destroy(h);
return res;
}

void await_resume() noexcept
if (auto & rec = h.promise().receiver; rec != nullptr)
{
if (generator->receiver)
generator->receiver->done = true;
if (!rec->done && !rec->exception)
rec->exception = detail::completed_unexpected();
rec->done = true;
rec->awaited_from.reset(nullptr);
rec = nullptr;
}
};

detail::self_destroy(h);
return res;
}

void await_resume() noexcept
{
if (generator->receiver)
generator->receiver->done = true;
}
};

auto final_suspend() noexcept
{
return final_awaitable{this};
}

Expand Down
1 change: 0 additions & 1 deletion include/boost/cobalt/detail/join.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ struct join_ranged_impl

struct awaitable : fork::shared_state
{

struct dummy
{
template<typename ... Args>
Expand Down
65 changes: 33 additions & 32 deletions include/boost/cobalt/detail/promise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,38 +320,6 @@ struct cobalt_promise
std::suspend_never initial_suspend() {return {};}
auto final_suspend() noexcept
{
struct final_awaitable
{
cobalt_promise * promise;
bool await_ready() const noexcept
{
return promise->receiver && promise->receiver->awaited_from.get() == nullptr;
}

std::coroutine_handle<void> await_suspend(std::coroutine_handle<cobalt_promise> h) noexcept
{
std::coroutine_handle<void> res = std::noop_coroutine();
if (promise->receiver && promise->receiver->awaited_from.get() != nullptr)
res = promise->receiver->awaited_from.release();


if (auto &rec = h.promise().receiver; rec != nullptr)
{
if (!rec->done && !rec->exception)
rec->exception = completed_unexpected();
rec->set_done();
rec->awaited_from.reset(nullptr);
rec = nullptr;
}
detail::self_destroy(h);
return res;
}

void await_resume() noexcept
{
}
};

return final_awaitable{this};
}

Expand All @@ -374,6 +342,39 @@ struct cobalt_promise
}

}
private:
struct final_awaitable
{
cobalt_promise * promise;
bool await_ready() const noexcept
{
return promise->receiver && promise->receiver->awaited_from.get() == nullptr;
}

std::coroutine_handle<void> await_suspend(std::coroutine_handle<cobalt_promise> h) noexcept
{
std::coroutine_handle<void> res = std::noop_coroutine();
if (promise->receiver && promise->receiver->awaited_from.get() != nullptr)
res = promise->receiver->awaited_from.release();


if (auto &rec = h.promise().receiver; rec != nullptr)
{
if (!rec->done && !rec->exception)
rec->exception = completed_unexpected();
rec->set_done();
rec->awaited_from.reset(nullptr);
rec = nullptr;
}
detail::self_destroy(h);
return res;
}

void await_resume() noexcept
{
}
};


};

Expand Down
Loading
Loading