YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
coro.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <yaclib/config.hpp>
4
5#if YACLIB_CORO == 2
6# include <coroutine>
7
8namespace yaclib_std {
9
10using std::coroutine_handle;
11using std::coroutine_traits;
12using std::suspend_always;
13using std::suspend_never;
14
15# if YACLIB_SYMMETRIC_TRANSFER != 0
16using std::noop_coroutine;
17# endif
18
19} // namespace yaclib_std
20#elif YACLIB_CORO == 1
21# include <experimental/coroutine>
22
23namespace yaclib_std {
24
25using std::experimental::coroutine_handle;
26using std::experimental::coroutine_traits;
27using std::experimental::suspend_always;
28using std::experimental::suspend_never;
29
30# if YACLIB_SYMMETRIC_TRANSFER != 0
31using std::experimental::noop_coroutine;
32# endif
33
34} // namespace yaclib_std
35#else
36# error "Don't have coroutine header"
37#endif
38
39#if YACLIB_SYMMETRIC_TRANSFER != 0
40# define YACLIB_TRANSFER(handle) \
41 return yaclib_std::coroutine_handle<> { \
42 handle \
43 }
44# define YACLIB_RESUME(handle) YACLIB_TRANSFER(handle)
45# define YACLIB_SUSPEND() YACLIB_TRANSFER(yaclib_std::noop_coroutine())
46#else
47namespace yaclib_std {
48
49constexpr yaclib_std::coroutine_handle<> noop_coroutine() noexcept {
50 return {};
51}
52
53} // namespace yaclib_std
54# define YACLIB_TRANSFER(handle) \
55 handle.resume(); \
56 return true
57# define YACLIB_RESUME(handle) return false
58# define YACLIB_SUSPEND() return true
59#endif
constexpr yaclib_std::coroutine_handle noop_coroutine() noexcept
Definition coro.hpp:49