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
fbbff11a
Commit
fbbff11a
authored
May 30, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve future.hpp
parent
bc8e0170
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
70 deletions
+73
-70
rt/include/typon/core/fork.hpp
rt/include/typon/core/fork.hpp
+1
-1
rt/include/typon/core/future.hpp
rt/include/typon/core/future.hpp
+72
-69
No files found.
rt/include/typon/core/fork.hpp
View file @
fbbff11a
...
...
@@ -102,7 +102,7 @@ namespace typon
{
continuation
.
children
().
insert
(
_coroutine
);
}
return
Future
<
promise_type
>
(
_coroutine
,
!
stolen
);
return
Future
<
T
>
(
_coroutine
,
!
stolen
);
}
};
...
...
rt/include/typon/core/future.hpp
View file @
fbbff11a
...
...
@@ -14,50 +14,50 @@
namespace
typon
{
template
<
typename
Promise
>
template
<
typename
T
>
struct
Future
{
using
value_type
=
typename
Promise
::
value_type
;
using
value_type
=
T
;
std
::
coroutine_handle
<
Promise
>
_coroutine
;
Result
<
T
>
*
_result
=
nullptr
;
union
{
value_type
_result
;
T
_value
;
};
template
<
typename
Promise
>
Future
(
std
::
coroutine_handle
<
Promise
>
coroutine
,
bool
ready
)
{
if
(
ready
)
{
fdt
::
defer
defer
{
[
&
coroutine
]()
{
coroutine
.
destroy
();
}
};
std
::
construct_at
(
std
::
addressof
(
_
result
),
coroutine
.
promise
().
get
());
std
::
construct_at
(
std
::
addressof
(
_
value
),
coroutine
.
promise
().
get
());
}
else
{
_
coroutine
=
coroutine
;
_
result
=
&
(
coroutine
.
promise
())
;
}
}
Future
(
Future
&&
other
)
noexcept
(
std
::
is_nothrow_move_constructible_v
<
value_type
>
)
Future
(
Future
&&
other
)
noexcept
(
std
::
is_nothrow_move_constructible_v
<
T
>
)
{
_
coroutine
=
other
.
_coroutine
;
if
(
!
_
coroutine
)
_
result
=
other
.
_result
;
if
(
!
_
result
)
{
std
::
construct_at
(
std
::
addressof
(
_
result
),
std
::
move
(
other
.
_result
));
std
::
construct_at
(
std
::
addressof
(
_
value
),
std
::
move
(
other
.
_value
));
}
}
Future
&
operator
=
(
Future
&&
other
)
noexcept
(
std
::
is_nothrow_move_constructible_v
<
value_type
>
)
noexcept
(
std
::
is_nothrow_move_constructible_v
<
T
>
)
{
if
(
this
!=
&
other
)
{
Future
old
{
std
::
move
(
*
this
)
};
_
coroutine
=
other
.
_coroutine
;
if
(
!
_
coroutine
)
_
result
=
other
.
_result
;
if
(
!
_
result
)
{
std
::
construct_at
(
std
::
addressof
(
_
result
),
std
::
move
(
other
.
_result
));
std
::
construct_at
(
std
::
addressof
(
_
value
),
std
::
move
(
other
.
_value
));
}
}
return
*
this
;
...
...
@@ -65,37 +65,39 @@ namespace typon
~
Future
()
{
if
(
!
_
coroutine
)
if
(
!
_
result
)
{
std
::
destroy_at
(
std
::
addressof
(
_
result
));
std
::
destroy_at
(
std
::
addressof
(
_
value
));
}
}
auto
get
()
T
get
()
{
if
(
_
coroutine
)
if
(
_
result
)
{
return
_
coroutine
.
promise
().
get
();
return
_
result
->
get
();
}
return
_
result
;
return
_
value
;
}
};
template
<
typename
Promise
>
requires
requires
{
sizeof
(
typename
Promise
::
value_type
);
}
&&
(
sizeof
(
typename
Promise
::
value_type
)
>
2
*
sizeof
(
void
*
))
struct
Future
<
Promise
>
template
<
typename
T
>
requires
requires
{
sizeof
(
T
);
}
&&
(
sizeof
(
T
)
>
2
*
sizeof
(
void
*
))
struct
Future
<
T
>
{
std
::
coroutine_handle
<
Promise
>
_coroutine
;
bool
_owning
;
using
value_type
=
T
;
Result
<
T
>
*
_result
=
nullptr
;
std
::
coroutine_handle
<>
_coroutine
;
template
<
typename
Promise
>
Future
(
std
::
coroutine_handle
<
Promise
>
coroutine
,
bool
ready
)
{
_coroutine
=
coroutine
;
_owning
=
ready
;
_result
=
&
(
coroutine
.
promise
());
if
(
ready
)
{
_coroutine
=
coroutine
;
if
(
coroutine
.
promise
().
_exception
)
{
std
::
rethrow_exception
(
coroutine
.
promise
().
_exception
);
...
...
@@ -107,54 +109,55 @@ namespace typon
Future
&
operator
=
(
const
Future
&
)
=
delete
;
Future
(
Future
&&
other
)
noexcept
:
_
coroutine
(
other
.
_coroutine
)
,
_
owning
(
std
::
exchange
(
other
.
_owning
,
false
))
:
_
result
(
other
.
_result
)
,
_
coroutine
(
std
::
exchange
(
other
.
_coroutine
,
nullptr
))
{}
Future
&
operator
=
(
Future
&&
other
)
noexcept
{
std
::
swap
(
_owning
,
other
.
_owning
);
std
::
swap
(
_coroutine
,
other
.
_coroutine
);
std
::
swap
(
_result
,
other
.
_result
);
return
*
this
;
}
~
Future
()
{
if
(
_
owning
)
if
(
_
coroutine
)
{
_coroutine
.
destroy
();
}
}
auto
get
()
T
get
()
{
return
_
coroutine
.
promise
().
get
();
return
_
result
->
get
();
}
};
template
<
typename
Promise
>
requires
std
::
is_trivially_copyable_v
<
typename
Promise
::
value_type
>
struct
Future
<
Promise
>
template
<
typename
T
>
requires
std
::
is_trivially_copyable_v
<
T
>
struct
Future
<
T
>
{
using
value_type
=
typename
Promise
::
value_type
;
using
value_type
=
T
;
std
::
coroutine_handle
<
Promise
>
_coroutine
;
Result
<
T
>
*
_result
=
nullptr
;
union
{
value_type
_
result
;
value_type
_
value
;
};
template
<
typename
Promise
>
Future
(
std
::
coroutine_handle
<
Promise
>
coroutine
,
bool
ready
)
{
if
(
ready
)
{
fdt
::
defer
defer
{
[
&
coroutine
]()
{
coroutine
.
destroy
();
}
};
std
::
construct_at
(
std
::
addressof
(
_
result
),
coroutine
.
promise
().
get
());
std
::
construct_at
(
std
::
addressof
(
_
value
),
coroutine
.
promise
().
get
());
}
else
{
_
coroutine
=
coroutine
;
_
result
=
&
(
coroutine
.
promise
())
;
}
}
...
...
@@ -163,64 +166,64 @@ namespace typon
~
Future
()
{
if
(
!
_
coroutine
)
if
(
!
_
result
)
{
std
::
destroy_at
(
std
::
addressof
(
_
result
));
std
::
destroy_at
(
std
::
addressof
(
_
value
));
}
}
auto
get
()
T
get
()
{
if
(
_
coroutine
)
if
(
_
result
)
{
return
_
coroutine
.
promise
().
get
();
return
_
result
->
get
();
}
return
_
result
;
return
_
value
;
}
};
template
<
typename
Promise
>
requires
std
::
is_reference_v
<
typename
Promise
::
value_type
>
struct
Future
<
Promise
>
template
<
typename
T
>
struct
Future
<
T
&>
{
using
value_type
=
typename
Promise
::
value_type
;
using
value_type
=
T
&
;
std
::
coroutine_handle
<
Promise
>
_coroutine
;
std
::
remove_reference
<
value_type
>
*
_result
;
Result
<
T
>
*
_result
=
nullptr
;
T
*
_value
;
template
<
typename
Promise
>
Future
(
std
::
coroutine_handle
<
Promise
>
coroutine
,
bool
ready
)
{
if
(
ready
)
{
fdt
::
defer
defer
{
[
&
coroutine
]()
{
coroutine
.
destroy
();
}
};
_
result
=
std
::
addressof
(
coroutine
.
promise
().
get
());
_
value
=
std
::
addressof
(
coroutine
.
promise
().
get
());
}
else
{
_
coroutine
=
coroutine
;
_
result
=
&
(
coroutine
.
promise
())
;
}
}
value_type
get
()
T
&
get
()
{
if
(
_
coroutine
)
if
(
_
result
)
{
return
_
coroutine
.
promise
().
get
();
return
_
result
->
get
();
}
return
*
_
result
;
return
*
_
value
;
}
};
template
<
typename
Promise
>
requires
std
::
is_void_v
<
typename
Promise
::
value_type
>
struct
Future
<
Promise
>
template
<
>
struct
Future
<
void
>
{
using
value_type
=
typename
Promise
::
value_type
;
using
value_type
=
void
;
std
::
coroutine_handle
<
Promise
>
_coroutine
;
Result
<
void
>
*
_result
=
nullptr
;
template
<
typename
Promise
>
Future
(
std
::
coroutine_handle
<
Promise
>
coroutine
,
bool
ready
)
{
if
(
ready
)
...
...
@@ -230,15 +233,15 @@ namespace typon
}
else
{
_
coroutine
=
coroutine
;
_
result
=
&
(
coroutine
.
promise
())
;
}
}
void
get
()
{
if
(
_
coroutine
)
if
(
_
result
)
{
_
coroutine
.
promise
().
get
();
_
result
->
get
();
}
}
};
...
...
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