Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tom Niget
typon
Commits
d997bff4
Commit
d997bff4
authored
Jul 11, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename parent.hpp into span.hpp
parent
a06701ba
Changes
3
Show 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 @
d997bff4
...
@@ -5,9 +5,9 @@
...
@@ -5,9 +5,9 @@
#include <cstdint>
#include <cstdint>
#include <typon/forked.hpp>
#include <typon/forked.hpp>
#include <typon/parent.hpp>
#include <typon/result.hpp>
#include <typon/result.hpp>
#include <typon/scheduler.hpp>
#include <typon/scheduler.hpp>
#include <typon/span.hpp>
namespace
typon
namespace
typon
...
@@ -17,7 +17,7 @@ namespace typon
...
@@ -17,7 +17,7 @@ namespace typon
struct
[[
nodiscard
]]
Fork
struct
[[
nodiscard
]]
Fork
{
{
struct
promise_type
;
struct
promise_type
;
using
u64
=
Parent
::
u64
;
using
u64
=
Span
::
u64
;
std
::
coroutine_handle
<
promise_type
>
_coroutine
;
std
::
coroutine_handle
<
promise_type
>
_coroutine
;
...
@@ -33,7 +33,7 @@ namespace typon
...
@@ -33,7 +33,7 @@ namespace typon
struct
promise_type
:
Result
<
T
>
struct
promise_type
:
Result
<
T
>
{
{
Parent
*
_parent
;
Span
*
_span
;
ForkList
::
Node
_node
;
ForkList
::
Node
_node
;
Fork
get_return_object
()
noexcept
Fork
get_return_object
()
noexcept
...
@@ -52,15 +52,15 @@ namespace typon
...
@@ -52,15 +52,15 @@ namespace typon
{
{
std
::
coroutine_handle
<>
await_suspend
(
std
::
coroutine_handle
<
promise_type
>
coroutine
)
noexcept
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
())
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
)
if
(
n
==
1
)
{
{
return
parent
->
continuation
();
return
span
->
continuation
();
}
}
return
std
::
noop_coroutine
();
return
std
::
noop_coroutine
();
}
}
...
@@ -87,22 +87,22 @@ namespace typon
...
@@ -87,22 +87,22 @@ namespace typon
template
<
typename
Promise
>
template
<
typename
Promise
>
auto
await_suspend
(
std
::
coroutine_handle
<
Promise
>
continuation
)
noexcept
auto
await_suspend
(
std
::
coroutine_handle
<
Promise
>
continuation
)
noexcept
{
{
Parent
*
parent
=
&
(
continuation
.
promise
().
_data
);
Span
*
span
=
&
(
continuation
.
promise
().
_span
);
_coroutine
.
promise
().
_
parent
=
parent
;
_coroutine
.
promise
().
_
span
=
span
;
_thefts
=
parent
->
_thefts
;
_thefts
=
span
->
_thefts
;
std
::
coroutine_handle
<>
on_stack_handle
=
_coroutine
;
std
::
coroutine_handle
<>
on_stack_handle
=
_coroutine
;
Scheduler
::
push
(
parent
);
Scheduler
::
push
(
span
);
return
on_stack_handle
;
return
on_stack_handle
;
}
}
auto
await_resume
()
auto
await_resume
()
{
{
auto
parent
=
_coroutine
.
promise
().
_parent
;
auto
span
=
_coroutine
.
promise
().
_span
;
bool
stolen
=
parent
->
_thefts
>
_thefts
;
bool
stolen
=
span
->
_thefts
>
_thefts
;
if
(
stolen
)
if
(
stolen
)
{
{
parent
->
_children
.
insert
(
_coroutine
);
span
->
_children
.
insert
(
_coroutine
);
}
}
return
Forked
<
T
>
(
_coroutine
,
!
stolen
);
return
Forked
<
T
>
(
_coroutine
,
!
stolen
);
}
}
...
...
rt/include/typon/join.hpp
View file @
d997bff4
...
@@ -4,8 +4,8 @@
...
@@ -4,8 +4,8 @@
#include <coroutine>
#include <coroutine>
#include <utility>
#include <utility>
#include <typon/parent.hpp>
#include <typon/result.hpp>
#include <typon/result.hpp>
#include <typon/span.hpp>
namespace
typon
namespace
typon
...
@@ -40,20 +40,20 @@ namespace typon
...
@@ -40,20 +40,20 @@ namespace typon
{
{
if
(
_coroutine
)
if
(
_coroutine
)
{
{
_coroutine
.
promise
().
_
data
.
_children
.
clear
();
_coroutine
.
promise
().
_
span
.
_children
.
clear
();
_coroutine
.
destroy
();
_coroutine
.
destroy
();
}
}
}
}
struct
promise_type
:
Result
<
T
>
struct
promise_type
:
Result
<
T
>
{
{
using
u64
=
Parent
::
u64
;
using
u64
=
Span
::
u64
;
static
constexpr
u64
UMAX
=
Parent
::
UMAX
;
static
constexpr
u64
UMAX
=
Span
::
UMAX
;
Parent
_data
;
Span
_span
;
promise_type
()
noexcept
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
Join
get_return_object
()
noexcept
...
@@ -76,13 +76,13 @@ namespace typon
...
@@ -76,13 +76,13 @@ namespace typon
{
{
struct
awaitable
struct
awaitable
{
{
Parent
&
_data
;
Span
&
_span
;
bool
await_ready
()
noexcept
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
)
if
(
n
-
(
UMAX
-
thefts
)
==
0
)
{
{
return
true
;
return
true
;
...
@@ -94,8 +94,8 @@ namespace typon
...
@@ -94,8 +94,8 @@ namespace typon
std
::
coroutine_handle
<>
await_suspend
(
std
::
coroutine_handle
<
promise_type
>
coroutine
)
noexcept
std
::
coroutine_handle
<>
await_suspend
(
std
::
coroutine_handle
<
promise_type
>
coroutine
)
noexcept
{
{
u64
thefts
=
_
data
.
_thefts
;
u64
thefts
=
_
span
.
_thefts
;
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
)
if
(
n
-
(
UMAX
-
thefts
)
==
0
)
{
{
return
coroutine
;
return
coroutine
;
...
@@ -105,13 +105,13 @@ namespace typon
...
@@ -105,13 +105,13 @@ namespace typon
void
await_resume
()
void
await_resume
()
{
{
_
data
.
_thefts
=
0
;
_
span
.
_thefts
=
0
;
_
data
.
_n
.
store
(
UMAX
,
std
::
memory_order_release
);
_
span
.
_n
.
store
(
UMAX
,
std
::
memory_order_release
);
_
data
.
_children
.
check_exceptions
();
_
span
.
_children
.
check_exceptions
();
}
}
};
};
return
awaitable
{
_
data
};
return
awaitable
{
_
span
};
}
}
auto
final_suspend
()
noexcept
auto
final_suspend
()
noexcept
...
@@ -120,16 +120,16 @@ namespace typon
...
@@ -120,16 +120,16 @@ namespace typon
{
{
std
::
coroutine_handle
<>
await_suspend
(
std
::
coroutine_handle
<
promise_type
>
coroutine
)
noexcept
std
::
coroutine_handle
<>
await_suspend
(
std
::
coroutine_handle
<
promise_type
>
coroutine
)
noexcept
{
{
Parent
&
data
=
coroutine
.
promise
().
_data
;
Span
&
span
=
coroutine
.
promise
().
_span
;
u64
thefts
=
data
.
_thefts
;
u64
thefts
=
span
.
_thefts
;
if
(
thefts
==
0
)
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
)
if
(
n
-
(
UMAX
-
thefts
)
==
0
)
{
{
return
data
.
_continuation
;
return
span
.
_continuation
;
}
}
return
std
::
noop_coroutine
();
return
std
::
noop_coroutine
();
}
}
...
@@ -152,13 +152,13 @@ namespace typon
...
@@ -152,13 +152,13 @@ namespace typon
std
::
coroutine_handle
<>
await_suspend
(
std
::
coroutine_handle
<>
continuation
)
noexcept
std
::
coroutine_handle
<>
await_suspend
(
std
::
coroutine_handle
<>
continuation
)
noexcept
{
{
_coroutine
.
promise
().
_
data
.
_continuation
=
continuation
;
_coroutine
.
promise
().
_
span
.
_continuation
=
continuation
;
return
_coroutine
;
return
_coroutine
;
}
}
decltype
(
auto
)
await_resume
()
decltype
(
auto
)
await_resume
()
{
{
_coroutine
.
promise
().
_
data
.
_children
.
check_exceptions
();
_coroutine
.
promise
().
_
span
.
_children
.
check_exceptions
();
return
_coroutine
.
promise
().
get
();
return
_coroutine
.
promise
().
get
();
}
}
};
};
...
...
rt/include/typon/
parent
.hpp
→
rt/include/typon/
span
.hpp
View file @
d997bff4
#ifndef TYPON_
PARENT
_HPP_INCLUDED
#ifndef TYPON_
SPAN
_HPP_INCLUDED
#define TYPON_
PARENT
_HPP_INCLUDED
#define TYPON_
SPAN
_HPP_INCLUDED
#include <atomic>
#include <atomic>
#include <concepts>
#include <concepts>
...
@@ -65,7 +65,7 @@ namespace typon
...
@@ -65,7 +65,7 @@ namespace typon
};
};
struct
Parent
:
Continuation
struct
Span
:
Continuation
{
{
using
u64
=
Continuation
::
u64
;
using
u64
=
Continuation
::
u64
;
...
@@ -77,7 +77,7 @@ namespace typon
...
@@ -77,7 +77,7 @@ namespace typon
std
::
atomic
<
u64
>
_n
=
UMAX
;
std
::
atomic
<
u64
>
_n
=
UMAX
;
Parent
(
std
::
coroutine_handle
<>
coroutine
)
noexcept
Span
(
std
::
coroutine_handle
<>
coroutine
)
noexcept
:
Continuation
(
coroutine
)
:
Continuation
(
coroutine
)
{}
{}
...
@@ -104,4 +104,4 @@ namespace typon
...
@@ -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