Skip to content

Commit

Permalink
first step on custom coro frame hacking.
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-morgenstern committed Mar 10, 2024
1 parent 820f9c3 commit f61014d
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ deps = [
'libs/concept_check',
'libs/config',
'libs/container',
'libs/context',
'libs/core',
'libs/date_time',
'libs/detail',
Expand Down
38 changes: 38 additions & 0 deletions include/boost/cobalt/experimental/fiber.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2023 Klemens D. Morgenstern
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_COBALT_FIBER_HPP
#define BOOST_COBALT_FIBER_HPP

#include <boost/context/fiber.hpp>

// this is all UB according to the standard. BUT it shouldn't be!

namespace boost::cobalt::experimental
{

namespace detail
{

struct fiber_promise
{

};

struct fiber_frame
{
void (*resume_) (fiber_frame *) = +[](fiber_frame * ff) { ff->resume();};
void (*destroy_)(fiber_frame *) = +[](fiber_frame * ff) { ff->destroy();};

fiber_promise promise;

void resume() {}
void destroy() {}
};

}

}

#endif //BOOST_COBALT_FIBER_HPP
7 changes: 6 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ add_test(NAME boost_cobalt_main COMMAND boost_cobalt_main)
add_test(NAME boost_cobalt_basic_tests COMMAND boost_cobalt_basic_tests)
target_compile_features(boost_cobalt PUBLIC cxx_std_20)

add_dependencies(tests boost_cobalt_main boost_cobalt_basic_tests boost_cobalt_static_tests)

add_executable(boost_cobalt_experimental test_main.cpp experimental/fiber.cpp)
target_link_libraries(boost_cobalt_experimental Boost::cobalt Boost::unit_test_framework Boost::context)
add_test(NAME boost_cobalt_experimental COMMAND boost_cobalt_experimental)

add_dependencies(tests boost_cobalt_main boost_cobalt_basic_tests boost_cobalt_static_tests boost_cobalt_experimental)
1 change: 1 addition & 0 deletions test/Jamfile.jam
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ for local src in [ glob *.cpp : main.cpp main_compile.cpp test_main.cpp concepts
run $(src) test_impl ;
}

run experimental/fiber.cpp test_impl ;
27 changes: 27 additions & 0 deletions test/experimental/fiber.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2023 Klemens D. Morgenstern
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/cobalt/experimental/fiber.hpp>

#include "../test.hpp"

BOOST_AUTO_TEST_SUITE(fiber);

BOOST_AUTO_TEST_CASE(basics)
{
boost::cobalt::experimental::detail::fiber_frame ff;

using pro = boost::cobalt::experimental::detail::fiber_promise;
auto hh = std::coroutine_handle<pro>::from_address(&ff);
BOOST_CHECK(!hh.done());
ff.resume_ = nullptr;
BOOST_CHECK(hh.done());

BOOST_CHECK(&ff.promise == &hh.promise());
BOOST_CHECK(std::coroutine_handle<pro>::from_promise(ff.promise).address() == &ff);
}


BOOST_AUTO_TEST_SUITE_END();

0 comments on commit f61014d

Please sign in to comment.