Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-concurrency
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
typon
typon-concurrency
Commits
7594bee5
Commit
7594bee5
authored
May 10, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor continuation.hpp
parent
1decadad
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
40 deletions
+46
-40
rt/include/typon/core/continuation.hpp
rt/include/typon/core/continuation.hpp
+33
-26
rt/include/typon/core/fork.hpp
rt/include/typon/core/fork.hpp
+3
-3
rt/include/typon/core/join.hpp
rt/include/typon/core/join.hpp
+5
-5
rt/include/typon/core/root.hpp
rt/include/typon/core/root.hpp
+2
-3
rt/include/typon/core/scheduler.hpp
rt/include/typon/core/scheduler.hpp
+3
-3
No files found.
rt/include/typon/core/continuation.hpp
View file @
7594bee5
...
...
@@ -2,6 +2,7 @@
#define TYPON_CORE_CONTINUATION_HPP_INCLUDED
#include <atomic>
#include <concepts>
#include <coroutine>
#include <cstdint>
#include <exception>
...
...
@@ -11,19 +12,23 @@
namespace
typon
{
struct
coroutine_node
struct
ForkList
{
coroutine_node
*
_next
;
struct
Node
{
Node
*
_next
;
std
::
coroutine_handle
<>
_coroutine
;
std
::
exception_ptr
*
_exception
;
};
struct
coroutine_list
{
coroutine_node
*
_first
=
nullptr
;
Node
*
_first
=
nullptr
;
template
<
typename
Promise
>
requires
requires
(
Promise
p
)
{
{
p
.
_exception
}
->
std
::
same_as
<
std
::
exception_ptr
&>
;
{
p
.
_node
}
->
std
::
same_as
<
Node
&>
;
}
void
insert
(
std
::
coroutine_handle
<
Promise
>
coroutine
)
noexcept
{
std
::
exception_ptr
*
exception
=
&
(
coroutine
.
promise
().
_exception
);
...
...
@@ -57,32 +62,33 @@ namespace typon
};
struct
continuation_data
struct
Continuation
{
struct
Data
{
using
u64
=
std
::
uint_fast64_t
;
static
constexpr
u64
UMAX
=
std
::
numeric_limits
<
u64
>::
max
();
std
::
coroutine_handle
<>
_coroutine
;
std
::
coroutine_handle
<>
_continuation
;
coroutine_list
_children
;
ForkList
_children
;
std
::
atomic
<
u64
>
_n
=
UMAX
;
u64
_thefts
=
0
;
continuation_data
(
std
::
coroutine_handle
<>
coroutine
)
Data
(
std
::
coroutine_handle
<>
coroutine
)
noexcept
:
_coroutine
(
coroutine
)
{}
};
Data
*
_data
;
struct
continuation_handle
{
continuation_data
*
_data
;
continuation_handle
()
noexcept
{}
Continuation
()
noexcept
{}
template
<
typename
Promise
>
continuation_handle
(
std
::
coroutine_handle
<
Promise
>
coroutine
)
noexcept
Continuation
(
std
::
coroutine_handle
<
Promise
>
coroutine
)
noexcept
:
_data
(
&
(
coroutine
.
promise
().
_data
))
{}
...
...
@@ -123,4 +129,5 @@ namespace typon
}
#endif // TYPON_CONTINUATION_HPP_INCLUDED
rt/include/typon/core/fork.hpp
View file @
7594bee5
...
...
@@ -17,7 +17,7 @@ namespace typon
struct
[[
nodiscard
]]
Fork
{
struct
promise_type
;
using
u64
=
continuation_d
ata
::
u64
;
using
u64
=
Continuation
::
D
ata
::
u64
;
std
::
coroutine_handle
<
promise_type
>
_coroutine
;
...
...
@@ -32,8 +32,8 @@ namespace typon
struct
promise_type
:
Result
<
T
>
{
continuation_handle
_continuation
;
coroutine_n
ode
_node
;
Continuation
_continuation
;
ForkList
::
N
ode
_node
;
Fork
get_return_object
()
noexcept
{
...
...
rt/include/typon/core/join.hpp
View file @
7594bee5
...
...
@@ -47,10 +47,10 @@ namespace typon
struct
promise_type
:
Result
<
T
>
{
using
u64
=
continuation_d
ata
::
u64
;
static
constexpr
u64
UMAX
=
continuation_d
ata
::
UMAX
;
using
u64
=
Continuation
::
D
ata
::
u64
;
static
constexpr
u64
UMAX
=
Continuation
::
D
ata
::
UMAX
;
continuation_d
ata
_data
;
Continuation
::
D
ata
_data
;
promise_type
()
noexcept
:
_data
(
std
::
coroutine_handle
<
promise_type
>::
from_promise
(
*
this
))
...
...
@@ -76,7 +76,7 @@ namespace typon
{
struct
awaitable
{
continuation_d
ata
&
_data
;
Continuation
::
D
ata
&
_data
;
bool
await_ready
()
noexcept
{
...
...
@@ -119,7 +119,7 @@ namespace typon
{
std
::
coroutine_handle
<>
await_suspend
(
std
::
coroutine_handle
<
promise_type
>
coroutine
)
noexcept
{
continuation_d
ata
&
data
=
coroutine
.
promise
().
_data
;
Continuation
::
D
ata
&
data
=
coroutine
.
promise
().
_data
;
u64
thefts
=
data
.
_thefts
;
u64
n
=
data
.
_n
.
fetch_sub
(
UMAX
-
thefts
,
std
::
memory_order_acq_rel
);
if
(
n
-
(
UMAX
-
thefts
)
==
0
)
...
...
rt/include/typon/core/root.hpp
View file @
7594bee5
...
...
@@ -27,8 +27,7 @@ namespace typon
struct
promise_type
:
Result
<
void
>
{
// std::atomic_bool _done = false;
continuation_data
_data
;
Continuation
::
Data
_data
;
promise_type
()
noexcept
:
_data
(
std
::
coroutine_handle
<
promise_type
>::
from_promise
(
*
this
))
...
...
@@ -64,7 +63,7 @@ namespace typon
{
Scheduler
::
get
();
Scheduler
::
schedule
(
_coroutine
);
_coroutine
.
promise
().
_data
.
_n
.
wait
(
continuation_d
ata
::
UMAX
,
std
::
memory_order_acquire
);
_coroutine
.
promise
().
_data
.
_n
.
wait
(
Continuation
::
D
ata
::
UMAX
,
std
::
memory_order_acquire
);
}
};
...
...
rt/include/typon/core/scheduler.hpp
View file @
7594bee5
...
...
@@ -21,7 +21,7 @@ namespace typon
struct
Scheduler
{
using
uint
=
unsigned
int
;
using
Deque
=
fdt
::
lock_free
::
deque
<
continuation_handle
>
;
using
Deque
=
fdt
::
lock_free
::
deque
<
Continuation
>
;
using
Task
=
typename
Deque
::
pop_type
;
static
inline
thread_local
uint
thread_id
;
...
...
@@ -40,12 +40,12 @@ namespace typon
return
scheduler
;
}
static
void
push
(
continuation_handle
task
)
noexcept
static
void
push
(
Continuation
task
)
noexcept
{
get
().
_deque
[
thread_id
].
push
(
task
);
}
static
void
schedule
(
continuation_handle
task
)
noexcept
static
void
schedule
(
Continuation
task
)
noexcept
{
Scheduler
&
scheduler
=
get
();
scheduler
.
_deque
[
thread_id
].
push
(
task
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment