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
1369f985
Commit
1369f985
authored
Feb 08, 2024
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow co_awaiting anything
parent
a5f699f1
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
73 additions
and
7 deletions
+73
-7
rt/examples/fork.cpp
rt/examples/fork.cpp
+1
-3
rt/examples/mutex.cpp
rt/examples/mutex.cpp
+1
-0
rt/include/typon/fork.hpp
rt/include/typon/fork.hpp
+3
-1
rt/include/typon/future.hpp
rt/include/typon/future.hpp
+1
-0
rt/include/typon/join.hpp
rt/include/typon/join.hpp
+11
-2
rt/include/typon/meta.hpp
rt/include/typon/meta.hpp
+39
-0
rt/include/typon/task.hpp
rt/include/typon/task.hpp
+17
-1
No files found.
rt/examples/fork.cpp
View file @
1369f985
#include <typon/typon.hpp>
#include <typon/logger.hpp>
#include <python/builtins.hpp>
#include <typon/generator.hpp>
using
namespace
typon
;
...
...
@@ -12,7 +10,7 @@ int fibo(int n) {
}
Task
<
void
>
hello
(
int
id
)
{
int
n
=
fibo
(
2
0
);
int
n
=
fibo
(
4
0
);
LOG
(
"hello(%d), fibo(20) = %d"
,
id
,
n
);
co_return
;
}
...
...
rt/examples/mutex.cpp
View file @
1369f985
...
...
@@ -23,6 +23,7 @@ Task<void> with_lock(int id)
LOG
(
"with_lock(%d), acquired"
,
id
);
int
n
=
fibo
(
N
);
LOG
(
"with_lock(%d), fibo(%d) = %d"
,
id
,
N
,
n
);
LOG
(
"with_lock(%d), releasing"
,
id
);
}
LOG
(
"with_lock(%d), released"
,
id
);
}
...
...
rt/include/typon/fork.hpp
View file @
1369f985
...
...
@@ -30,7 +30,9 @@ namespace typon
Fork
(
std
::
coroutine_handle
<
promise_type
>
coroutine
)
noexcept
:
_coroutine
(
coroutine
)
{}
{
static_assert
(
meta
::
Awaitable
<
Fork
>
);
}
Fork
(
const
Fork
&
)
=
delete
;
Fork
&
operator
=
(
const
Fork
&
)
=
delete
;
...
...
rt/include/typon/future.hpp
View file @
1369f985
...
...
@@ -6,6 +6,7 @@
#include <cstdint>
#include <utility>
#include <typon/meta.hpp>
#include <typon/result.hpp>
#include <typon/scheduler.hpp>
#include <typon/stack.hpp>
...
...
rt/include/typon/join.hpp
View file @
1369f985
...
...
@@ -24,7 +24,9 @@ namespace typon
coroutine_type
_coroutine
;
Join
(
coroutine_type
coroutine
)
noexcept
:
_coroutine
(
coroutine
)
{}
Join
(
coroutine_type
coroutine
)
noexcept
:
_coroutine
(
coroutine
)
{
static_assert
(
meta
::
Awaitable
<
Join
>
);
}
Join
(
const
Join
&
)
=
delete
;
Join
&
operator
=
(
const
Join
&
)
=
delete
;
...
...
@@ -73,12 +75,19 @@ namespace typon
_span
.
set_sequential_exception
(
std
::
current_exception
());
}
template
<
typenam
e
U
>
template
<
meta
::
Awaitabl
e
U
>
decltype
(
auto
)
await_transform
(
U
&&
expr
)
noexcept
{
return
std
::
forward
<
U
>
(
expr
);
}
template
<
typename
U
>
requires
(
!
meta
::
Awaitable
<
U
>
)
decltype
(
auto
)
await_transform
(
U
&&
expr
)
noexcept
{
return
meta
::
AwaitReady
{
std
::
forward
<
U
>
(
expr
)};
}
auto
await_transform
(
Sync
&&
)
noexcept
{
struct
awaitable
...
...
rt/include/typon/meta.hpp
View file @
1369f985
#ifndef TYPON_META_HPP_INCLUDED
#define TYPON_META_HPP_INCLUDED
#include <coroutine>
#include <type_traits>
namespace
typon
::
meta
{
struct
Empty
{};
template
<
typename
T
>
concept
Awaiter
=
requires
(
T
&&
a
,
std
::
coroutine_handle
<
void
>
h
)
{
// simplified
a
.
await_ready
();
a
.
await_suspend
(
h
);
a
.
await_resume
();
};
template
<
typename
T
>
concept
Awaitable
=
Awaiter
<
std
::
remove_cvref_t
<
T
>>
||
requires
(
T
&&
a
)
{
// simplified
std
::
forward
<
T
>
(
a
).
operator
co_await
();
};
template
<
typename
T
>
requires
(
!
Awaitable
<
T
>
)
struct
AwaitReady
:
std
::
suspend_never
{
T
_ready
;
AwaitReady
()
=
delete
;
AwaitReady
(
const
AwaitReady
&
)
=
delete
;
AwaitReady
&
operator
=
(
const
AwaitReady
&
)
=
delete
;
AwaitReady
(
T
&&
ready
)
:
_ready
(
std
::
move
(
ready
))
{}
AwaitReady
(
const
T
&
ready
)
:
_ready
(
ready
)
{}
T
await_resume
()
noexcept
{
return
std
::
move
(
_ready
);
}
};
}
...
...
rt/include/typon/task.hpp
View file @
1369f985
...
...
@@ -4,6 +4,7 @@
#include <coroutine>
#include <utility>
#include <typon/meta.hpp>
#include <typon/result.hpp>
...
...
@@ -17,7 +18,9 @@ namespace typon
std
::
coroutine_handle
<
promise_type
>
_coroutine
;
Task
(
std
::
coroutine_handle
<
promise_type
>
coroutine
)
noexcept
:
_coroutine
(
coroutine
)
{}
Task
(
std
::
coroutine_handle
<
promise_type
>
coroutine
)
noexcept
:
_coroutine
(
coroutine
)
{
static_assert
(
meta
::
Awaitable
<
Task
>
);
}
Task
(
const
Task
&
)
=
delete
;
Task
&
operator
=
(
const
Task
&
)
=
delete
;
...
...
@@ -54,6 +57,19 @@ namespace typon
return
{};
}
template
<
meta
::
Awaitable
U
>
decltype
(
auto
)
await_transform
(
U
&&
expr
)
noexcept
{
return
std
::
forward
<
U
>
(
expr
);
}
template
<
typename
U
>
requires
(
!
meta
::
Awaitable
<
U
>
)
decltype
(
auto
)
await_transform
(
U
&&
expr
)
noexcept
{
return
meta
::
AwaitReady
{
std
::
forward
<
U
>
(
expr
)};
}
auto
final_suspend
()
noexcept
{
struct
awaitable
:
std
::
suspend_always
...
...
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