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