Skip to content

Commit

Permalink
removed boost.context support and added yield_context integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-morgenstern committed Apr 21, 2024
1 parent 4aee1ca commit c97859f
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 474 deletions.
3 changes: 0 additions & 3 deletions doc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ include::reference/config.adoc[]
include::reference/leaf.adoc[]

include::reference/experimental/context.adoc[]
include::reference/experimental/fiber.adoc[]
include::reference/experimental/continuation.adoc[]



= In-Depth
Expand Down
63 changes: 0 additions & 63 deletions doc/reference/experimental/continuation.adoc

This file was deleted.

63 changes: 0 additions & 63 deletions doc/reference/experimental/fiber.adoc

This file was deleted.

41 changes: 18 additions & 23 deletions include/boost/cobalt/experimental/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include <boost/context/fixedsize_stack.hpp>

#include <boost/cobalt/concepts.hpp>
#include <boost/cobalt/experimental/frame.hpp>
#include <boost/cobalt/config.hpp>
#include <coroutine>
#include <new>
// this is all UB according to the standard. BUT it shouldn't be!

namespace boost::cobalt::experimental
{
Expand All @@ -25,25 +25,20 @@ namespace detail
{

template<typename Promise>
struct fiber_frame
struct context_frame : frame<context_frame<Promise>, Promise>
{
void (*resume_) (fiber_frame *) = +[](fiber_frame * ff) { ff->resume();};
void (*destroy_)(fiber_frame *) = +[](fiber_frame * ff) { ff->destroy();};

Promise promise;

boost::context::fiber caller, callee;

void (*after_resume)(fiber_frame *, void *) = nullptr;
void (*after_resume)(context_frame *, void *) = nullptr;
void * after_resume_p;

template<typename ... Args>
requires std::constructible_from<Promise, Args...>
fiber_frame(Args && ... args) : promise(args...) {}
context_frame(Args && ... args) : frame<context_frame, Promise>(args...) {}

template<typename ... Args>
requires (!std::constructible_from<Promise, Args...> && std::is_default_constructible_v<Promise>)
fiber_frame(Args && ...) {}
context_frame(Args && ...) {}

void resume()
{
Expand All @@ -54,13 +49,13 @@ struct fiber_frame
void destroy()
{
auto c = std::exchange(callee, {});
this->~fiber_frame();
this->~context_frame();
}

template<typename Awaitable>
auto do_resume(void * )
{
return +[](fiber_frame * this_, void * p)
return +[](context_frame * this_, void * p)
{
auto aw_ = static_cast<Awaitable*>(p);
auto h = std::coroutine_handle<Promise>::from_address(this_) ;
Expand All @@ -71,7 +66,7 @@ struct fiber_frame
template<typename Awaitable>
auto do_resume(bool * )
{
return +[](fiber_frame * this_, void * p)
return +[](context_frame * this_, void * p)
{
auto aw_ = static_cast<Awaitable*>(p);
auto h = std::coroutine_handle<Promise>::from_address(this_) ;
Expand All @@ -83,7 +78,7 @@ struct fiber_frame
template<typename Awaitable, typename Promise_>
auto do_resume(std::coroutine_handle<Promise_> * )
{
return +[](fiber_frame * this_, void * p)
return +[](context_frame * this_, void * p)
{
auto aw_ = static_cast<Awaitable*>(p);
auto h = std::coroutine_handle<Promise>::from_address(this_) ;
Expand Down Expand Up @@ -277,14 +272,14 @@ struct context

private:

context(detail::fiber_frame<promise_type> * frame) : frame_(frame) {}
context(detail::context_frame<promise_type> * frame) : frame_(frame) {}
template<typename, typename ...>
friend struct context;

//template<typename >
friend struct detail::fiber_frame<promise_type>;
friend struct detail::context_frame<promise_type>;

detail::fiber_frame<promise_type> * frame_;
detail::context_frame<promise_type> * frame_;
};

template<typename Return, typename ... Args, std::invocable<context<Return, Args...>, Args...> Func, typename StackAlloc>
Expand All @@ -293,17 +288,17 @@ auto make_context(Func && func, std::allocator_arg_t, StackAlloc && salloc, Arg
auto sctx_ = salloc.allocate();

using promise_type = typename std::coroutine_traits<Return, Args...>::promise_type;
void * p = static_cast<char*>(sctx_.sp) - sizeof(detail::fiber_frame<promise_type>);
auto sz = sctx_.size - sizeof(detail::fiber_frame<promise_type>);
void * p = static_cast<char*>(sctx_.sp) - sizeof(detail::context_frame<promise_type>);
auto sz = sctx_.size - sizeof(detail::context_frame<promise_type>);

if (auto diff = reinterpret_cast<std::uintptr_t>(p) % alignof(detail::fiber_frame<promise_type>); diff != 0u)
if (auto diff = reinterpret_cast<std::uintptr_t>(p) % alignof(detail::context_frame<promise_type>); diff != 0u)
{
p = static_cast<char*>(p) - diff;
sz -= diff;
}

boost::context::preallocated psc{p, sz, sctx_};
auto f = new (p) detail::fiber_frame<promise_type>(args...);
auto f = new (p) detail::context_frame<promise_type>(args...);

auto res = f->promise.get_return_object();

Expand All @@ -313,11 +308,11 @@ auto make_context(Func && func, std::allocator_arg_t, StackAlloc && salloc, Arg

struct invoker
{
detail::fiber_frame<promise_type> * frame;
detail::context_frame<promise_type> * frame;
mutable Func func;
mutable std::tuple<Args...> args;

invoker(detail::fiber_frame<promise_type> * frame, Func && func, Args && ... args)
invoker(detail::context_frame<promise_type> * frame, Func && func, Args && ... args)
: frame(frame), func(std::forward<Func>(func)), args(std::forward<Args>(args)...)
{
}
Expand Down
70 changes: 0 additions & 70 deletions include/boost/cobalt/experimental/continuation.hpp

This file was deleted.

Loading

0 comments on commit c97859f

Please sign in to comment.