[coroutines] Add std::experimental::task<T> type
authorBrian Gesiak <modocache@gmail.com>
Tue, 26 Mar 2019 17:46:06 +0000 (17:46 +0000)
committerBrian Gesiak <modocache@gmail.com>
Tue, 26 Mar 2019 17:46:06 +0000 (17:46 +0000)
commit57839425aa4802986acbb17392ca697ee76aa633
tree9e173f9d545ee0dd2a54e5a7fca96a216130cc39
parent52221d56bcf3d087bb88d44b56c682fd27f59a13
[coroutines] Add std::experimental::task<T> type

Summary:
Adds the coroutine `std::experimental::task<T>` type described in proposal P1056R0.
See https://wg21.link/P1056R0.

This implementation allows customization of the allocator used to allocate the
coroutine frame by passing std::allocator_arg as the first argument, followed by
the allocator to use.

This supports co_awaiting the same task multiple times. The second and
subsequent times it returns a reference to the already-computed value.

This diff also adds some implementations of other utilities that have potential for
standardization as helpers within the test/... area:
- `sync_wait(awaitable)` - See P1171R0
- `manual_reset_event`

Move the definition of the __aligned_allocation_size helper function
from <experimental/memory_resource> to <experimental/__memory>
so it can be more widely used without pulling in memory_resource.

Outstanding work:
- Use C++14 keywords directly rather than macro versions
  eg. use `noexcept` instead of `_NOEXCEPT`).
- Add support for overaligned coroutine frames.
  This may need wording in the Coroutines TS to support passing the extra `std::align_val_t`.
- Eliminate use of `if constexpr` if we want it to compile under C++14.

Patch by @lewissbaker (Lewis Baker).

llvm-svn: 357010
15 files changed:
libcxx/include/CMakeLists.txt
libcxx/include/experimental/__memory
libcxx/include/experimental/memory_resource
libcxx/include/experimental/task [new file with mode: 0644]
libcxx/include/module.modulemap
libcxx/test/std/experimental/task/awaitable_traits.hpp [new file with mode: 0644]
libcxx/test/std/experimental/task/counted.hpp [new file with mode: 0644]
libcxx/test/std/experimental/task/lit.local.cfg [new file with mode: 0644]
libcxx/test/std/experimental/task/manual_reset_event.hpp [new file with mode: 0644]
libcxx/test/std/experimental/task/sync_wait.hpp [new file with mode: 0644]
libcxx/test/std/experimental/task/task.basic/task_custom_allocator.pass.cpp [new file with mode: 0644]
libcxx/test/std/experimental/task/task.basic/task_of_value.pass.cpp [new file with mode: 0644]
libcxx/test/std/experimental/task/task.basic/task_of_void.pass.cpp [new file with mode: 0644]
libcxx/test/std/experimental/task/task.lifetime/task_parameter_lifetime.pass.cpp [new file with mode: 0644]
libcxx/test/std/experimental/task/task.lifetime/task_return_value_lifetime.pass.cpp [new file with mode: 0644]