5 #include <libcopp/utils/config/libcopp_build_features.h>
9 #ifdef LIBCOPP_MACRO_USE_SEGMENTED_STACKS
10 # define COROUTINE_CONTEXT_BASE_USING_BASE_SEGMENTED_STACKS(base_type) using base_type::caller_stack_;
12 # define COROUTINE_CONTEXT_BASE_USING_BASE_SEGMENTED_STACKS(base_type)
15 #define COROUTINE_CONTEXT_BASE_USING_BASE(base_type) \
17 using base_type::caller_; \
18 using base_type::callee_; \
19 using base_type::callee_stack_; \
20 COROUTINE_CONTEXT_BASE_USING_BASE_SEGMENTED_STACKS(base_type)
22 LIBCOPP_COPP_NAMESPACE_BEGIN
28 using ptr_type = LIBCOPP_COPP_NAMESPACE_ID::util::intrusive_ptr<coroutine_context>;
46 #if defined(LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR) && LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR
47 using coroutine_context_base::unhandle_exception_;
63 #ifdef LIBCOPP_MACRO_USE_SEGMENTED_STACKS
89 size_t coroutine_size,
size_t private_buffer_size) LIBCOPP_MACRO_NOEXCEPT;
91 template <typename TRunner>
93 size_t coroutine_size,
94 size_t private_buffer_size) LIBCOPP_MACRO_NOEXCEPT {
96 p, [runner](
void *private_data) {
return (*runner)(private_data); }, callee_stack, coroutine_size,
106 LIBCOPP_COPP_API
int start(
void *priv_data =
nullptr);
108 #if defined(LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR) && LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR
115 LIBCOPP_COPP_API
int start(std::exception_ptr &unhandled,
void *priv_data =
nullptr) LIBCOPP_MACRO_NOEXCEPT;
124 LIBCOPP_COPP_API
int resume(
void *priv_data =
nullptr);
126 #if defined(LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR) && LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR
133 LIBCOPP_COPP_API
int resume(std::exception_ptr &unhandled,
void *priv_data =
nullptr) LIBCOPP_MACRO_NOEXCEPT;
141 LIBCOPP_COPP_API
int yield(
void **priv_data =
nullptr) LIBCOPP_MACRO_NOEXCEPT;
158 template <
typename Tc>
159 LIBCOPP_COPP_API_HEAD_ONLY Tc *
get() {
168 LIBCOPP_COPP_API
int yield(
void **priv_data =
nullptr) LIBCOPP_MACRO_NOEXCEPT;
170 LIBCOPP_COPP_NAMESPACE_END
base type of all coroutine context
size_t private_buffer_size_
LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type< int > status_
std::function< int(void *)> callback_type
base type of all stackful coroutine context
LIBCOPP_COPP_API coroutine_context() LIBCOPP_MACRO_NOEXCEPT
coroutine_context_base::flag_type flag_type
fcontext::fcontext_t caller_
stack_context callee_stack_
LIBCOPP_COPP_API int start(void *priv_data=nullptr)
start coroutine
LIBCOPP_COPP_API int yield(void **priv_data=nullptr) LIBCOPP_MACRO_NOEXCEPT
yield coroutine
LIBCOPP_COPP_API int resume(void *priv_data=nullptr)
resume coroutine
LIBCOPP_COPP_NAMESPACE_ID::util::intrusive_ptr< coroutine_context > ptr_type
fcontext::fcontext_t callee_
coroutine_context_base::callback_type callback_type
static LIBCOPP_COPP_API int create(coroutine_context *p, callback_type &&runner, const stack_context &callee_stack, size_t coroutine_size, size_t private_buffer_size) LIBCOPP_MACRO_NOEXCEPT
create coroutine context at stack context callee_
coroutine_context_base::status_type status_type
LIBCOPP_COPP_API_HEAD_ONLY Tc * get()
get current coroutine and try to convert type
LIBCOPP_COPP_API coroutine_context * get_coroutine() LIBCOPP_MACRO_NOEXCEPT
get current coroutine
coroutine_context * from_co
coroutine_context * to_co
status of safe coroutine context base