Skip to content

Commit

Permalink
added generate-diagram option & cache
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-morgenstern committed Jul 2, 2024
1 parent 5e3ef2f commit e6a5dec
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ else()

file(GLOB_RECURSE ADOC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.adoc)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html
COMMAND asciidoctor ${CMAKE_CURRENT_SOURCE_DIR}/doc/index.adoc --require asciidoctor-diagram --require asciidoctor-multipage -b multipage_html5 -o ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html
COMMAND asciidoctor ${CMAKE_CURRENT_SOURCE_DIR}/doc/index.adoc --require asciidoctor-diagram --require asciidoctor-multipage -b multipage_html5 -a generate-diagram -o ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html
DEPENDS ${ADOC_FILES})

add_custom_target(boost_cobalt_doc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html)
Expand Down
2 changes: 1 addition & 1 deletion doc/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import asciidoctor ;

html index.html : index.adoc : <flags>"-r asciidoctor-diagram" ;
html index.html : index.adoc ;

install html_ : index.html : <location>html ;

Expand Down
19 changes: 14 additions & 5 deletions doc/background/lazy_eager.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Coro Done
resumed twice
----


[mermaid]
ifdef::generate-diagram[]
[mermaid, target=lazy_eager1]
----
sequenceDiagram
participant main;
Expand All @@ -54,6 +54,11 @@ sequenceDiagram
lazy->>main: co_return
Note left of main: "resumed twice"
----
endif::[]

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


Whereas an eager coro would look like this:
Expand Down Expand Up @@ -90,8 +95,8 @@ Coro Done
----



[mermaid]
ifdef::generate-diagram[]
[mermaid, target=lazy_eager2]
----
sequenceDiagram
participant main;
Expand All @@ -104,5 +109,9 @@ sequenceDiagram
Note right of lazy: "Coro done"
lazy->>main: co_return
Note left of main: "resumed once"
----
endif::[]

----
ifndef::generate-diagram[]
image::{docdir}/images/lazy_eager2.png[]
endif::[]
17 changes: 15 additions & 2 deletions doc/background/stackless.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ main()
bar()
----

[mermaid]
ifdef::generate-diagram[]
[mermaid, target=stackless1]
----
sequenceDiagram
main->>+foo: call
foo->>+bar: call
bar->>-foo: return
foo->>-main: return
----
endif::[]

ifndef::generate-diagram[]
image::{docdir}/images/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.
C++20 coroutines are stackless, i.e. they only allocate their own frame and use the callers stack on resumption. Using our previous example:
Expand Down Expand Up @@ -75,7 +81,9 @@ main()
f$example()
----

[mermaid]

ifdef::generate-diagram[]
[mermaid, target=stackless2]
----
sequenceDiagram
participant main
Expand All @@ -89,5 +97,10 @@ sequenceDiagram
main-->>example: resume
example->>-main: co_return
----
endif::[]

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

The same applies if a coroutine gets moved accross threads.
Binary file added doc/images/awaitables.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/generators1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/generators2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/lazy_eager1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/lazy_eager2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/stackless1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/stackless2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions doc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Version 0.1, 29.01.2023
:source-language: c++
:example-caption: Example

:imagesdir: {docdir}/images

:leveloffset: +1

Expand Down
9 changes: 7 additions & 2 deletions doc/primer/awaitables.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ NOTE: Type will be implicitly converted into an awaitable if there is an `operat
This documentation will use `awaitable` to include these types,
and "actual_awaitable" to refer to type conforming to the above prototype.


[mermaid]
ifdef::generate-diagram[]
[mermaid, target=awaitables]
----
flowchart TD
aw{await_ready?}
aw ---->|true| ar[await_resume]
aw -->|false| as[await_suspend]
as -->|Resume| ar
----
endif::[]

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

In a `co_await` expression the waiting coroutine will first invoke
`await_ready` to check if the coroutine needs to suspend.
Expand Down
17 changes: 15 additions & 2 deletions doc/reference/generators.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ Which will generate the following output
In coro 3
In main 4

[mermaid]

ifdef::generate-diagram[]
[mermaid, target=generators1]
----
sequenceDiagram
participant main;
Expand All @@ -47,6 +49,11 @@ sequenceDiagram
example->>main: co_return 3
Note left of main: "In main 4"
----
endif::[]

ifndef::generate-diagram[]
image::{docdir}/images/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 @@ -117,7 +124,8 @@ Which will generate the following output
In coro 3
In main 4

[mermaid]
ifdef::generate-diagram[]
[mermaid, target=generators2]
----
sequenceDiagram
participant main;
Expand All @@ -131,6 +139,11 @@ sequenceDiagram
example->>main: co_return 3
Note left of main: "In main 4"
----
endif::[]

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

[#generator-executor]
=== Executor
Expand Down

0 comments on commit e6a5dec

Please sign in to comment.