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
Xavier Thompson
typon-concurrency
Commits
3f3c9f45
Commit
3f3c9f45
authored
Jul 11, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename parent.hpp into span.hpp
parent
c0202255
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
41 deletions
+41
-41
rt/include/typon/fork.hpp
rt/include/typon/fork.hpp
+14
-14
rt/include/typon/join.hpp
rt/include/typon/join.hpp
+22
-22
rt/include/typon/span.hpp
rt/include/typon/span.hpp
+5
-5
No files found.
rt/include/typon/fork.hpp
View file @
3f3c9f45
...
...
@@ -5,9 +5,9 @@
#include <cstdint>
#include <typon/forked.hpp>
#include <typon/parent.hpp>
#include <typon/result.hpp>
#include <typon/scheduler.hpp>
#include <typon/span.hpp>
namespace
typon
...
...
@@ -17,7 +17,7 @@ namespace typon
struct
[[
nodiscard
]]
Fork
{
struct
promise_type
;
using
u64
=
Parent
::
u64
;
using
u64
=
Span
::
u64
;
std
::
coroutine_handle
<
promise_type
>
_coroutine
;
...
...
@@ -33,7 +33,7 @@ namespace typon
struct
promise_type
:
Result
<
T
>
{
Parent
*
_parent
;
Span
*
_span
;
ForkList
::
Node
_node
;
Fork
get_return_object
()
noexcept
...
...
@@ -52,15 +52,15 @@ namespace typon
{
std
::
coroutine_handle
<>
await_suspend
(
std
::
coroutine_handle
<
promise_type
>
coroutine
)
noexcept
{
auto
parent
=
coroutine
.
promise
().
_parent
;
auto
span
=
coroutine
.
promise
().
_span
;
if
(
Scheduler
::
pop
())
{
return
parent
->
_coroutine
;
return
span
->
_coroutine
;
}
u64
n
=
parent
->
_n
.
fetch_sub
(
1
,
std
::
memory_order_acq_rel
);
u64
n
=
span
->
_n
.
fetch_sub
(
1
,
std
::
memory_order_acq_rel
);
if
(
n
==
1
)
{
return
parent
->
continuation
();
return
span
->
continuation
();
}
return
std
::
noop_coroutine
();
}
...
...
@@ -87,22 +87,22 @@ namespace typon
template
<
typename
Promise
>
auto
await_suspend
(
std
::
coroutine_handle
<
Promise
>
continuation
)
noexcept
{
Parent
*
parent
=
&
(
continuation
.
promise
().
_data
);
_coroutine
.
promise
().
_
parent
=
parent
;
_thefts
=
parent
->
_thefts
;
Span
*
span
=
&
(
continuation
.
promise
().
_span
);
_coroutine
.
promise
().
_
span
=
span
;
_thefts
=
span
->
_thefts
;
std
::
coroutine_handle
<>
on_stack_handle
=
_coroutine
;
Scheduler
::
push
(
parent
);
Scheduler
::
push
(
span
);
return
on_stack_handle
;
}
auto
await_resume
()
{
auto
parent
=
_coroutine
.
promise
().
_parent
;
bool
stolen
=
parent
->
_thefts
>
_thefts
;
auto
span
=
_coroutine
.
promise
().
_span
;
bool
stolen
=
span
->
_thefts
>
_thefts
;
if
(
stolen
)
{
parent
->
_children
.
insert
(
_coroutine
);
span
->
_children
.
insert
(
_coroutine
);
}
return
Forked
<
T
>
(
_coroutine
,
!
stolen
);
}
...
...
rt/include/typon/join.hpp
View file @
3f3c9f45
...
...
@@ -4,8 +4,8 @@
#include <coroutine>
#include <utility>
#include <typon/parent.hpp>
#include <typon/result.hpp>
#include <typon/span.hpp>
namespace
typon
...
...
@@ -40,20 +40,20 @@ namespace typon
{
if
(
_coroutine
)
{
_coroutine
.
promise
().
_
data
.
_children
.
clear
();
_coroutine
.
promise
().
_
span
.
_children
.
clear
();
_coroutine
.
destroy
();
}
}
struct
promise_type
:
Result
<
T
>
{
using
u64
=
Parent
::
u64
;
static
constexpr
u64
UMAX
=
Parent
::
UMAX
;
using
u64
=
Span
::
u64
;
static
constexpr
u64
UMAX
=
Span
::
UMAX
;
Parent
_data
;
Span
_span
;
promise_type
()
noexcept
:
_
data
(
std
::
coroutine_handle
<
promise_type
>::
from_promise
(
*
this
))
:
_
span
(
std
::
coroutine_handle
<
promise_type
>::
from_promise
(
*
this
))
{}
Join
get_return_object
()
noexcept
...
...
@@ -76,13 +76,13 @@ namespace typon
{
struct
awaitable
{
Parent
&
_data
;
Span
&
_span
;
bool
await_ready
()
noexcept
{
if
(
u64
thefts
=
_
data
.
_thefts
)
if
(
u64
thefts
=
_
span
.
_thefts
)
{
u64
n
=
_
data
.
_n
.
load
(
std
::
memory_order_acquire
);
u64
n
=
_
span
.
_n
.
load
(
std
::
memory_order_acquire
);
if
(
n
-
(
UMAX
-
thefts
)
==
0
)
{
return
true
;
...
...
@@ -94,8 +94,8 @@ namespace typon
std
::
coroutine_handle
<>
await_suspend
(
std
::
coroutine_handle
<
promise_type
>
coroutine
)
noexcept
{
u64
thefts
=
_
data
.
_thefts
;
u64
n
=
_
data
.
_n
.
fetch_sub
(
UMAX
-
thefts
,
std
::
memory_order_acq_rel
);
u64
thefts
=
_
span
.
_thefts
;
u64
n
=
_
span
.
_n
.
fetch_sub
(
UMAX
-
thefts
,
std
::
memory_order_acq_rel
);
if
(
n
-
(
UMAX
-
thefts
)
==
0
)
{
return
coroutine
;
...
...
@@ -105,13 +105,13 @@ namespace typon
void
await_resume
()
{
_
data
.
_thefts
=
0
;
_
data
.
_n
.
store
(
UMAX
,
std
::
memory_order_release
);
_
data
.
_children
.
check_exceptions
();
_
span
.
_thefts
=
0
;
_
span
.
_n
.
store
(
UMAX
,
std
::
memory_order_release
);
_
span
.
_children
.
check_exceptions
();
}
};
return
awaitable
{
_
data
};
return
awaitable
{
_
span
};
}
auto
final_suspend
()
noexcept
...
...
@@ -120,16 +120,16 @@ namespace typon
{
std
::
coroutine_handle
<>
await_suspend
(
std
::
coroutine_handle
<
promise_type
>
coroutine
)
noexcept
{
Parent
&
data
=
coroutine
.
promise
().
_data
;
u64
thefts
=
data
.
_thefts
;
Span
&
span
=
coroutine
.
promise
().
_span
;
u64
thefts
=
span
.
_thefts
;
if
(
thefts
==
0
)
{
return
data
.
_continuation
;
return
span
.
_continuation
;
}
u64
n
=
data
.
_n
.
fetch_sub
(
UMAX
-
thefts
,
std
::
memory_order_acq_rel
);
u64
n
=
span
.
_n
.
fetch_sub
(
UMAX
-
thefts
,
std
::
memory_order_acq_rel
);
if
(
n
-
(
UMAX
-
thefts
)
==
0
)
{
return
data
.
_continuation
;
return
span
.
_continuation
;
}
return
std
::
noop_coroutine
();
}
...
...
@@ -152,13 +152,13 @@ namespace typon
std
::
coroutine_handle
<>
await_suspend
(
std
::
coroutine_handle
<>
continuation
)
noexcept
{
_coroutine
.
promise
().
_
data
.
_continuation
=
continuation
;
_coroutine
.
promise
().
_
span
.
_continuation
=
continuation
;
return
_coroutine
;
}
decltype
(
auto
)
await_resume
()
{
_coroutine
.
promise
().
_
data
.
_children
.
check_exceptions
();
_coroutine
.
promise
().
_
span
.
_children
.
check_exceptions
();
return
_coroutine
.
promise
().
get
();
}
};
...
...
rt/include/typon/
parent
.hpp
→
rt/include/typon/
span
.hpp
View file @
3f3c9f45
#ifndef TYPON_
PARENT
_HPP_INCLUDED
#define TYPON_
PARENT
_HPP_INCLUDED
#ifndef TYPON_
SPAN
_HPP_INCLUDED
#define TYPON_
SPAN
_HPP_INCLUDED
#include <atomic>
#include <concepts>
...
...
@@ -65,7 +65,7 @@ namespace typon
};
struct
Parent
:
Continuation
struct
Span
:
Continuation
{
using
u64
=
Continuation
::
u64
;
...
...
@@ -77,7 +77,7 @@ namespace typon
std
::
atomic
<
u64
>
_n
=
UMAX
;
Parent
(
std
::
coroutine_handle
<>
coroutine
)
noexcept
Span
(
std
::
coroutine_handle
<>
coroutine
)
noexcept
:
Continuation
(
coroutine
)
{}
...
...
@@ -104,4 +104,4 @@ namespace typon
}
#endif // TYPON_
PARENT
_HPP_INCLUDED
#endif // TYPON_
SPAN
_HPP_INCLUDED
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