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

Boost 1.87 #211

Merged
merged 13 commits into from
Oct 30, 2024
Merged
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
1 change: 1 addition & 0 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ deps = [
'libs/mp11',
'libs/numeric',
'libs/optional',
'libs/pool',
'libs/predef',
'libs/preprocessor',
'libs/range',
Expand Down
19 changes: 19 additions & 0 deletions boost-cobalt.jam
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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)


import feature ;


feature.feature boost.cobalt.pmr : std boost-container custom no : propagated composite ;
feature.compose <boost.cobalt.pmr>std : <define>BOOST_COBALT_USE_STD_PMR=1 ;
feature.compose <boost.cobalt.pmr>boost-container : <define>BOOST_COBALT_USE_BOOST_CONTAINER_PMR=1 ;
feature.compose <boost.cobalt.pmr>custom : <define>BOOST_COBALT_USE_CUSTOM_PMR=1 ;
feature.compose <boost.cobalt.pmr>no : <define>BOOST_COBALT_NO_PMR=1 ;

feature.feature boost.cobalt.executor : any_io_executor use_io_context custom : propagated composite ;
feature.compose <boost.cobalt.executor>any_io_executor : ;
feature.compose <boost.cobalt.executor>use_io_context : <define>BOOST_COBALT_USE_IO_CONTEXT=1 ;
feature.compose <boost.cobalt.executor>custom_executor : <define>BOOST_COBALT_CUSTOM_EXECUTOR=1 ;
37 changes: 37 additions & 0 deletions build.jam
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright René Ferdinand Rivera Morell 2024
# 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)

require-b2 5.2 ;

constant boost_dependencies :
/boost/asio//boost_asio
/boost/callable_traits//boost_callable_traits
/boost/circular_buffer//boost_circular_buffer
/boost/config//boost_config
/boost/container//boost_container
/boost/context//boost_context
/boost/core//boost_core
/boost/intrusive//boost_intrusive
/boost/leaf//boost_leaf
/boost/mp11//boost_mp11
/boost/preprocessor//boost_preprocessor
/boost/smart_ptr//boost_smart_ptr
/boost/system//boost_system
/boost/throw_exception//boost_throw_exception
/boost/variant2//boost_variant2 ;

project /boost/cobalt
: common-requirements
<include>include
;

explicit
[ alias boost_cobalt : build//boost_cobalt ]
[ alias all : boost_cobalt test example ]
;

call-if : boost-library cobalt
;

28 changes: 9 additions & 19 deletions build/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@


import os ;
import feature ;
import ../../config/checks/config : requires ;
import-search /boost/config/checks ;
import config : requires ;
import-search /boost/cobalt ;
import boost-cobalt ;


project : requirements
Expand All @@ -17,20 +19,10 @@ project : requirements
<target-os>windows:<define>WIN32_LEAN_AND_MEAN
<target-os>linux:<linkflags>-lpthread
: source-location ../src
: common-requirements <library>$(boost_dependencies)
;


feature.feature boost.cobalt.pmr : std boost-container custom no : propagated composite ;
feature.compose <boost.cobalt.pmr>std : <define>BOOST_COBALT_USE_STD_PMR=1 ;
feature.compose <boost.cobalt.pmr>boost-container : <define>BOOST_COBALT_USE_BOOST_CONTAINER_PMR=1 ;
feature.compose <boost.cobalt.pmr>custom : <define>BOOST_COBALT_USE_CUSTOM_PMR=1 ;
feature.compose <boost.cobalt.pmr>no : <define>BOOST_COBALT_NO_PMR=1 ;

feature.feature boost.cobalt.executor : any_io_executor use_io_context custom : propagated composite ;
feature.compose <boost.cobalt.executor>any_io_executor : ;
feature.compose <boost.cobalt.executor>use_io_context : <define>BOOST_COBALT_USE_IO_CONTEXT=1 ;
feature.compose <boost.cobalt.executor>custom_executor : <define>BOOST_COBALT_CUSTOM_EXECUTOR=1 ;

local config-binding = [ modules.binding config ] ;
config-binding ?= "" ;

Expand All @@ -50,10 +42,10 @@ lib boost_cobalt
: cobalt_sources
: requirements <define>BOOST_COBALT_SOURCE=1
<link>shared:<define>BOOST_COBALT_DYN_LINK=1
[ requires
[ requires
cxx20_hdr_concepts
]
<boost.cobalt.pmr>boost-container:<library>/boost//container
<boost.cobalt.pmr>boost-container:<library>/boost/container//boost_container
[ check-target-builds
$(config-binding:D)//cpp_lib_memory_resource
cpp_lib_memory_resource
Expand All @@ -62,8 +54,9 @@ lib boost_cobalt
]

: usage-requirements
<boost.cobalt.pmr>boost-container:<library>/boost//container
<boost.cobalt.pmr>boost-container:<library>/boost/container//boost_container
<link>shared:<define>BOOST_COBALT_DYN_LINK=1
<define>BOOST_COBALT_NO_LINK=1
[ check-target-builds
$(config-binding:D)//cpp_lib_memory_resource
cpp_lib_memory_resource
Expand Down Expand Up @@ -97,6 +90,3 @@ rule set-pmr-std ( props * )
return <boost.cobalt.pmr>std ;
}
}

boost-install boost_cobalt ;

13 changes: 13 additions & 0 deletions doc/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ explicit cobalt.pdf ;
install pdf_ : cobalt.pdf : <location>pdf ;
explicit pdf_ ;

install images
:
images/awaitables.png
images/generators1.png
images/generators2.png
images/lazy_eager1.png
images/lazy_eager2.png
images/stackless1.png
images/stackless2.png
:
<location>html/images
;

alias boostdoc ;
explicit boostdoc ;
alias boostrelease : html_ ;
Expand Down
4 changes: 2 additions & 2 deletions doc/background/lazy_eager.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ sequenceDiagram
endif::[]

ifndef::generate-diagram[]
image::{docdir}/images/lazy_eager1.png[]
image::lazy_eager1.png[]
endif::[]


Expand Down Expand Up @@ -113,5 +113,5 @@ sequenceDiagram
endif::[]

ifndef::generate-diagram[]
image::{docdir}/images/lazy_eager2.png[]
image::lazy_eager2.png[]
endif::[]
4 changes: 2 additions & 2 deletions doc/background/stackless.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ sequenceDiagram
endif::[]

ifndef::generate-diagram[]
image::{docdir}/images/stackless1.png[]
image::stackless1.png[]
endif::[]

Coroutines can be implemented a stackful, which means that it allocates a fixes chunk of memory and stacks function frames similar to a thread.
Expand Down Expand Up @@ -100,7 +100,7 @@ sequenceDiagram
endif::[]

ifndef::generate-diagram[]
image::{docdir}/images/stackless2.png[]
image::stackless2.png[]
endif::[]

The same applies if a coroutine gets moved accross threads.
2 changes: 1 addition & 1 deletion doc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Version 0.1, 29.01.2023
:source-language: c++
:example-caption: Example

:imagesdir: {docdir}/images
:imagesdir: ./images

:leveloffset: +1

Expand Down
2 changes: 1 addition & 1 deletion doc/overview.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Here's a list of relevant features in cobalt:
|API reference
|Look up details while coding

|<<technical_background>>
|<<in_depth>>
|Some implementation details
|Read if you're not confused enough

Expand Down
2 changes: 1 addition & 1 deletion doc/primer/awaitables.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ flowchart TD
endif::[]

ifndef::generate-diagram[]
image::{docdir}/images/awaitables.png[]
image::awaitables.png[]
endif::[]

In a `co_await` expression the waiting coroutine will first invoke
Expand Down
4 changes: 2 additions & 2 deletions doc/reference/generators.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ sequenceDiagram
endif::[]

ifndef::generate-diagram[]
image::{docdir}/images/generators1.png[]
image::generators1.png[]
endif::[]

Values can be pushed into the generator, when `Push` (the second template parameter) is set to non-void:
Expand Down Expand Up @@ -142,7 +142,7 @@ sequenceDiagram
endif::[]

ifndef::generate-diagram[]
image::{docdir}/images/generators2.png[]
image::generators2.png[]
endif::[]

[#generator-executor]
Expand Down
2 changes: 1 addition & 1 deletion doc/tour/promise.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cobalt::main co_main(int argc, char * argv[])
// do something else here
co_await do_the_other_thing();
// wait for the promise to complete
auto res = co_wait p;
auto res = co_await p;

co_return res;
}
Expand Down
2 changes: 1 addition & 1 deletion doc/tour/task.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cobalt::main co_main(int argc, char * argv[])
// do something else here first
co_await do_the_other_thing();
// start and wait for the task to complete
auto res = co_wait t;
auto res = co_await t;
co_return res;
}
----
Expand Down
19 changes: 10 additions & 9 deletions example/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@


import os ;
import-search /boost/cobalt ;
import boost-cobalt ;


project : requirements
Expand All @@ -18,12 +20,11 @@ project : requirements
<toolset>clang-14:<boost.cobalt.pmr>boost-container
;

exe channel : channel.cpp /boost//cobalt ;
exe delay : delay.cpp /boost//cobalt ;
exe delay_op : delay_op.cpp /boost//cobalt ;
exe echo_server : echo_server.cpp /boost//cobalt ;
exe outcome : outcome.cpp /boost//cobalt ;
exe thread : thread.cpp /boost//cobalt ;
exe thread_pool : thread_pool.cpp /boost//cobalt ;
# exe ticker : ticker.cpp /boost//json /boost//cobalt ;

exe channel : channel.cpp /boost/cobalt//boost_cobalt ;
exe delay : delay.cpp /boost/cobalt//boost_cobalt ;
exe delay_op : delay_op.cpp /boost/cobalt//boost_cobalt ;
exe echo_server : echo_server.cpp /boost/cobalt//boost_cobalt ;
exe outcome : outcome.cpp /boost/cobalt//boost_cobalt /boost/outcome//boost_outcome ;
exe thread : thread.cpp /boost/cobalt//boost_cobalt ;
exe thread_pool : thread_pool.cpp /boost/cobalt//boost_cobalt ;
# exe ticker : ticker.cpp /boost/cobalt//boost_cobalt /boost/json//boost_json ;
28 changes: 28 additions & 0 deletions include/boost/cobalt/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ struct channel
this->unlink();
}

void interrupt_await()
{
this->cancelled = true;
if (awaited_from)
awaited_from.release().resume();
}

struct cancel_impl;
bool await_ready() { return !chn->buffer_.empty(); }
template<typename Promise>
Expand Down Expand Up @@ -118,6 +125,13 @@ struct channel
this->unlink();
}

void interrupt_await()
{
this->cancelled = true;
if (awaited_from)
awaited_from.release().resume();
}

struct cancel_impl;

bool await_ready() { return !chn->buffer_.full(); }
Expand Down Expand Up @@ -234,6 +248,13 @@ struct channel<void>
this->unlink();
}

void interrupt_await()
{
this->cancelled = true;
if (awaited_from)
awaited_from.release().resume();
}

struct cancel_impl;
bool await_ready() { return (chn->n_ > 0); }
template<typename Promise>
Expand Down Expand Up @@ -261,6 +282,13 @@ struct channel<void>
this->unlink();
}

void interrupt_await()
{
this->cancelled = true;
if (awaited_from)
awaited_from.release().resume();
}

struct cancel_impl;
bool await_ready()
{
Expand Down
7 changes: 4 additions & 3 deletions include/boost/cobalt/detail/fork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <boost/intrusive_ptr.hpp>

#include <coroutine>
#include <optional>

namespace boost::cobalt::detail
{
Expand Down Expand Up @@ -56,13 +57,13 @@ struct fork

bool outstanding_work() {return use_count != 0u;}

const executor * exec = nullptr;
bool wired_up() {return exec != nullptr;}
std::optional<executor> exec;
bool wired_up() {return exec.has_value();}

using executor_type = executor;
const executor_type & get_executor() const
{
BOOST_ASSERT(exec != nullptr);
BOOST_ASSERT(exec.has_value());
return *exec;
}

Expand Down
4 changes: 2 additions & 2 deletions include/boost/cobalt/detail/gather.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ struct gather_variadic_impl
#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
this->loc = loc;
#endif
this->exec = &cobalt::detail::get_executor(h);
this->exec = cobalt::detail::get_executor(h);
last_forked.release().resume();
while (last_index < tuple_size)
impls[last_index++](*this).release();
Expand Down Expand Up @@ -362,7 +362,7 @@ struct gather_ranged_impl
#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
this->loc = loc;
#endif
exec = &detail::get_executor(h);
exec = detail::get_executor(h);

last_forked.release().resume();
while (last_index < cancel.size())
Expand Down
Loading
Loading