|
libcopp 2.3.1
|
coroutine container contain stack context, stack allocator and runtime fcontext More...
#include <coroutine_context_container.h>


Public Types | |
| using | coroutine_context_type = coroutine_context |
| using | base_type = coroutine_context |
| using | allocator_type = TALLOC |
| using | this_type = coroutine_context_container< allocator_type > |
| using | ptr_type = LIBCOPP_COPP_NAMESPACE_ID::memory::intrusive_ptr< this_type > |
| using | callback_type = coroutine_context::callback_type |
| using | ptr_t = ptr_type |
| using | callback_t = callback_type |
| using | status_type = coroutine_context_base::status_type |
| using | flag_type = coroutine_context_base::flag_type |
| using | status_t = status_type |
| using | flag_t = flag_type |
Public Member Functions | |
| ~coroutine_context_container () | |
| const allocator_type & | get_allocator () const LIBCOPP_MACRO_NOEXCEPT |
| get stack allocator | |
| allocator_type & | get_allocator () LIBCOPP_MACRO_NOEXCEPT |
| get stack allocator | |
| size_t | use_count () const LIBCOPP_MACRO_NOEXCEPT |
| LIBCOPP_COPP_API int | start (void *priv_data=nullptr) |
| start coroutine | |
| LIBCOPP_COPP_API int | resume (void *priv_data=nullptr) |
| resume coroutine | |
| LIBCOPP_COPP_API int | yield (void **priv_data=nullptr) LIBCOPP_MACRO_NOEXCEPT |
| yield coroutine | |
| template<class TAWAITABLE , class TERROR_TRANSFORM , class = nostd::enable_if_t<stackful_inject_awaitable<nostd::remove_cvref_t<TAWAITABLE>>::value>> | |
| LIBCOPP_COPP_API_HEAD_ONLY container_value_type< TAWAITABLE > | await_value (TAWAITABLE &&awaitable, TERROR_TRANSFORM &&error_transform) noexcept(std::is_nothrow_copy_constructible< container_value_type< TAWAITABLE > >::value &&noexcept(error_transform(COPP_EC_ARGS_ERROR))) |
| Waits for the specified awaitable object to finish and retrieves its result. | |
| template<class TAWAITABLE , class = nostd::enable_if_t<stackful_inject_awaitable<nostd::remove_cvref_t<TAWAITABLE>>::value>> | |
| LIBCOPP_COPP_API_HEAD_ONLY container_value_type< TAWAITABLE > | await_value (TAWAITABLE &&awaitable) noexcept(std::is_nothrow_copy_constructible< container_value_type< TAWAITABLE > >::value &&noexcept(stackful_channel_error_transform< container_value_type< TAWAITABLE > >()(COPP_EC_ARGS_ERROR))) |
| Waits for the specified awaitable object to finish and retrieves its result. | |
| LIBCOPP_COPP_API bool | set_flags (int flags) LIBCOPP_MACRO_NOEXCEPT |
| set all flags to true | |
| LIBCOPP_COPP_API bool | unset_flags (int flags) LIBCOPP_MACRO_NOEXCEPT |
| set all flags to false | |
| LIBCOPP_COPP_API bool | check_flags (int flags) const LIBCOPP_MACRO_NOEXCEPT |
| check flags | |
| LIBCOPP_COPP_API int | set_runner (callback_type &&runner) |
| set runner | |
| LIBCOPP_UTIL_FORCEINLINE const std::function< int(void *)> & | get_runner () const LIBCOPP_MACRO_NOEXCEPT |
| LIBCOPP_UTIL_FORCEINLINE int | get_ret_code () const LIBCOPP_MACRO_NOEXCEPT |
| get runner return code | |
| LIBCOPP_COPP_API bool | is_finished () const LIBCOPP_MACRO_NOEXCEPT |
| get runner return code | |
| LIBCOPP_UTIL_FORCEINLINE void * | get_private_buffer () const LIBCOPP_MACRO_NOEXCEPT |
| get private buffer(raw pointer) | |
| LIBCOPP_UTIL_FORCEINLINE size_t | get_private_buffer_size () const LIBCOPP_MACRO_NOEXCEPT |
| get private buffer size | |
Static Public Member Functions | |
| static ptr_type | create (callback_type &&runner, allocator_type &alloc, size_t stack_sz=0, size_t private_buffer_size=0, size_t coroutine_size=0) LIBCOPP_MACRO_NOEXCEPT |
| create and init coroutine with specify runner and specify stack size | |
| template<class TRunner > | |
| static ptr_type | create (TRunner *runner, allocator_type &alloc, size_t stack_size=0, size_t private_buffer_size=0, size_t coroutine_size=0) LIBCOPP_MACRO_NOEXCEPT |
| static ptr_type | create (int(*fn)(void *), allocator_type &alloc, size_t stack_size=0, size_t private_buffer_size=0, size_t coroutine_size=0) LIBCOPP_MACRO_NOEXCEPT |
| static ptr_type | create (callback_type &&runner, size_t stack_size=0, size_t private_buffer_size=0, size_t coroutine_size=0) LIBCOPP_MACRO_NOEXCEPT |
| template<class TRunner > | |
| static ptr_type | create (TRunner *runner, size_t stack_size=0, size_t private_buffer_size=0, size_t coroutine_size=0) LIBCOPP_MACRO_NOEXCEPT |
| static ptr_type | create (int(*fn)(void *), size_t stack_size=0, size_t private_buffer_size=0, size_t coroutine_size=0) LIBCOPP_MACRO_NOEXCEPT |
| 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_ | |
| template<typename TRunner > | |
| static LIBCOPP_COPP_API_HEAD_ONLY int | create (coroutine_context *p, TRunner *runner, const stack_context &callee_stack, size_t coroutine_size, size_t private_buffer_size) LIBCOPP_MACRO_NOEXCEPT |
| static LIBCOPP_UTIL_FORCEINLINE size_t | align_private_data_size (size_t sz) |
| static size_t | align_address_size (size_t sz) |
| static size_t | align_stack_size (size_t sz) |
| static LIBCOPP_COPP_API coroutine_context_base * | get_this_coroutine_base () LIBCOPP_MACRO_NOEXCEPT |
| get current coroutine | |
| static LIBCOPP_COPP_API void | set_this_coroutine_base (coroutine_context_base *ctx) LIBCOPP_MACRO_NOEXCEPT |
| set current coroutine | |
Protected Member Functions | |
| LIBCOPP_UTIL_FORCEINLINE void | run_and_recv_retcode (void *priv_data) |
| coroutine entrance function | |
Protected Attributes | |
| fcontext::fcontext_t | caller_ |
| fcontext::fcontext_t | callee_ |
| stack_context | callee_stack_ |
Private Member Functions | |
| coroutine_context_container (const allocator_type &alloc) LIBCOPP_MACRO_NOEXCEPT | |
| coroutine_context_container (allocator_type &&alloc) LIBCOPP_MACRO_NOEXCEPT | |
| coroutine_context_container (const coroutine_context_container &)=delete | |
Private Attributes | |
| allocator_type | alloc_ |
| LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type< LIBCOPP_COPP_NAMESPACE_ID::util::lock::unsafe_int_type< size_t > > | ref_count_ |
| int | flags_ |
| void * | priv_data_ |
| size_t | private_buffer_size_ |
| callback_type | runner_ |
| int | runner_ret_code_ |
| LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type< LIBCOPP_COPP_NAMESPACE_ID::util::lock::unsafe_int_type< int > > | status_ |
Friends | |
| void | intrusive_ptr_add_ref (this_type *p) |
| void | intrusive_ptr_release (this_type *p) |
coroutine container contain stack context, stack allocator and runtime fcontext
Definition at line 26 of file coroutine_context_container.h.
| using coroutine_context_container< TALLOC >::allocator_type = TALLOC |
Definition at line 30 of file coroutine_context_container.h.
| using coroutine_context_container< TALLOC >::base_type = coroutine_context |
Definition at line 29 of file coroutine_context_container.h.
| using coroutine_context_container< TALLOC >::callback_t = callback_type |
Definition at line 37 of file coroutine_context_container.h.
| using coroutine_context_container< TALLOC >::callback_type = coroutine_context::callback_type |
Definition at line 33 of file coroutine_context_container.h.
| using coroutine_context_container< TALLOC >::coroutine_context_type = coroutine_context |
Definition at line 28 of file coroutine_context_container.h.
|
inherited |
Definition at line 39 of file coroutine_context.h.
|
inherited |
Definition at line 33 of file coroutine_context.h.
| using coroutine_context_container< TALLOC >::ptr_t = ptr_type |
Definition at line 36 of file coroutine_context_container.h.
| using coroutine_context_container< TALLOC >::ptr_type = LIBCOPP_COPP_NAMESPACE_ID::memory::intrusive_ptr<this_type> |
Definition at line 32 of file coroutine_context_container.h.
|
inherited |
Definition at line 38 of file coroutine_context.h.
|
inherited |
Definition at line 32 of file coroutine_context.h.
| using coroutine_context_container< TALLOC >::this_type = coroutine_context_container<allocator_type> |
Definition at line 31 of file coroutine_context_container.h.
|
inlineprivate |
Definition at line 42 of file coroutine_context_container.h.
|
inlineprivate |
Definition at line 44 of file coroutine_context_container.h.
|
inline |
Definition at line 48 of file coroutine_context_container.h.
|
privatedelete |
|
inlinestaticinherited |
Definition at line 223 of file coroutine_context_base.h.
References COROUTINE_CONTEXT_BASE_ALIGN_UNIT_SIZE.
Referenced by coroutine_context_container< TALLOC >::create().
|
inlinestaticinherited |
Definition at line 207 of file coroutine_context_base.h.
References COROUTINE_CONTEXT_BASE_ALIGN_UNIT_SIZE.
Referenced by coroutine_context_container< TALLOC >::create().
|
inlinestaticinherited |
Definition at line 231 of file coroutine_context_base.h.
References COROUTINE_CONTEXT_STACK_ALIGN_UNIT_SIZE.
|
inlinenoexceptinherited |
Waits for the specified awaitable object to finish and retrieves its result.
| awaitable | The awaitable object to be consumed. |
Definition at line 172 of file coroutine_context.h.
|
inlinenoexceptinherited |
Waits for the specified awaitable object to finish and retrieves its result.
| awaitable | The awaitable object to be consumed. |
| error_transform | A callable object used to transform error code to return type if any occur. |
Definition at line 156 of file coroutine_context.h.
|
inherited |
check flags
| flags | flags to be checked |
Definition at line 98 of file coroutine_context.cpp.
Referenced by this_coroutine::get_coroutine(), and coroutine_context::start().
|
inlinestatic |
create and init coroutine with specify runner and specify stack size
| runner | runner |
| stack_sz | stack size |
| private_buffer_size | private buffer size |
| coroutine_size | extend buffer before coroutine |
Definition at line 71 of file coroutine_context_container.h.
References coroutine_context_base::align_address_size(), coroutine_context_base::align_private_data_size(), coroutine_context::create(), stack_traits::default_size(), stack_context::reset(), and stack_context::sp.
Referenced by coroutine_context_container< TALLOC >::create(), coroutine_context_container< TALLOC >::create(), coroutine_context_container< TALLOC >::create(), coroutine_context_container< TALLOC >::create(), coroutine_context_container< TALLOC >::create(), main(), and main().
|
inlinestatic |
Definition at line 138 of file coroutine_context_container.h.
References coroutine_context_container< TALLOC >::create().
|
staticinherited |
create coroutine context at stack context callee_
| runner | runner |
| callee_stack | stack context |
| coroutine_size | size of coroutine object |
| private_buffer_size | size of private buffer |
Definition at line 284 of file coroutine_context.cpp.
References COPP_EC_ARGS_ERROR, COPP_EC_FCONTEXT_MAKE_FAILED, COPP_EC_SUCCESS, fcontext::copp_make_fcontext_v2(), and libcopp_internal_api_set::coroutine_context_callback().
Referenced by coroutine_context_container< TALLOC >::create(), and coroutine_context::create().
|
inlinestaticinherited |
Definition at line 94 of file coroutine_context.h.
References coroutine_context::create().
|
inlinestatic |
Definition at line 129 of file coroutine_context_container.h.
References coroutine_context_container< TALLOC >::create().
|
inlinestatic |
Definition at line 151 of file coroutine_context_container.h.
References coroutine_context_container< TALLOC >::create().
|
inlinestatic |
Definition at line 119 of file coroutine_context_container.h.
References coroutine_context_container< TALLOC >::create().
|
inlinestatic |
Definition at line 145 of file coroutine_context_container.h.
References coroutine_context_container< TALLOC >::create().
|
inline |
get stack allocator
Definition at line 54 of file coroutine_context_container.h.
References coroutine_context_container< TALLOC >::alloc_.
|
inline |
get stack allocator
Definition at line 60 of file coroutine_context_container.h.
References coroutine_context_container< TALLOC >::alloc_.
|
inlineinherited |
get private buffer(raw pointer)
Definition at line 197 of file coroutine_context_base.h.
References coroutine_context_base::priv_data_.
|
inlineinherited |
get private buffer size
Definition at line 202 of file coroutine_context_base.h.
References coroutine_context_base::private_buffer_size_.
|
inlineinherited |
get runner return code
Definition at line 186 of file coroutine_context_base.h.
References coroutine_context_base::runner_ret_code_.
|
inlineinherited |
get runner of this coroutine context (const)
Definition at line 178 of file coroutine_context_base.h.
References coroutine_context_base::runner_.
|
staticinherited |
get current coroutine
Definition at line 123 of file coroutine_context.cpp.
References detail::get_this_coroutine_context().
|
inherited |
get runner return code
Definition at line 118 of file coroutine_context.cpp.
References coroutine_context_base::status_type::EN_CRS_FINISHED, and coroutine_context_base::status_.
|
inherited |
resume coroutine
| priv_data | private data, will be passed to runner operator() or return to yield |
| if | exception is enabled, it will throw all unhandled exception after resumed |
Definition at line 416 of file coroutine_context.cpp.
References coroutine_context::start().
|
inlineprotectedinherited |
coroutine entrance function
Definition at line 160 of file coroutine_context_base.h.
References coroutine_context_base::runner_, and coroutine_context_base::runner_ret_code_.
Referenced by libcopp_internal_api_set::coroutine_context_callback().
|
inherited |
set all flags to true
| flags | (flags & EN_CFT_MASK) must be 0 |
Definition at line 80 of file coroutine_context.cpp.
|
inherited |
set runner
| runner |
Definition at line 102 of file coroutine_context.cpp.
References COPP_EC_ALREADY_INITED, COPP_EC_ARGS_ERROR, COPP_EC_SUCCESS, coroutine_context_base::status_type::EN_CRS_INVALID, coroutine_context_base::status_type::EN_CRS_READY, coroutine_context_base::runner_, and coroutine_context_base::status_.
|
staticinherited |
set current coroutine
| ctx | pointer of current coroutine, if not in coroutine, set nullptr |
Definition at line 127 of file coroutine_context.cpp.
References detail::set_this_coroutine_context().
|
inherited |
start coroutine
| priv_data | private data, will be passed to runner operator() or return to yield |
| if | exception is enabled, it will throw all unhandled exception after resumed |
Definition at line 348 of file coroutine_context.cpp.
References coroutine_context::callee_, coroutine_context::callee_stack_, coroutine_context_base::check_flags(), COPP_EC_IS_RUNNING, COPP_EC_NOT_INITED, COPP_EC_NOT_READY, COPP_EC_SUCCESS, coroutine_context_base::flag_type::EN_CFT_FINISHED, coroutine_context_base::flag_type::EN_CFT_IS_FIBER, coroutine_context_base::status_type::EN_CRS_EXITED, coroutine_context_base::status_type::EN_CRS_READY, coroutine_context_base::status_type::EN_CRS_RUNNING, coroutine_context::jump_src_data_t::from_co, detail::get_this_coroutine_context(), jump_to(), LIBCOPP_UTIL_UNLIKELY_CONDITION, coroutine_context::jump_src_data_t::priv_data, coroutine_context::status_, std::swap(), and coroutine_context::jump_src_data_t::to_co.
Referenced by coroutine_context::resume().
|
inherited |
set all flags to false
| flags | (flags & EN_CFT_MASK) must be 0 |
Definition at line 89 of file coroutine_context.cpp.
|
inline |
Definition at line 156 of file coroutine_context_container.h.
References coroutine_context_container< TALLOC >::ref_count_.
|
inherited |
yield coroutine
| priv_data | private data, if not nullptr, will get the value from start(priv_data) or resume(priv_data) |
Definition at line 423 of file coroutine_context.cpp.
References COPP_EC_ALREADY_EXIST, COPP_EC_NOT_INITED, COPP_EC_NOT_RUNNING, COPP_EC_SUCCESS, COPP_EC_UNKNOWN, coroutine_context::jump_src_data_t::from_co, jump_to(), coroutine_context::jump_src_data_t::priv_data, and coroutine_context::jump_src_data_t::to_co.
Referenced by libcopp_internal_api_set::coroutine_context_callback(), and this_coroutine::yield().
|
friend |
Definition at line 162 of file coroutine_context_container.h.
|
friend |
Definition at line 170 of file coroutine_context_container.h.
|
private |
Definition at line 189 of file coroutine_context_container.h.
Referenced by coroutine_context_container< TALLOC >::get_allocator(), and coroutine_context_container< TALLOC >::get_allocator().
|
protectedinherited |
caller runtime context
Definition at line 62 of file coroutine_context.h.
Referenced by libcopp_internal_api_set::coroutine_context_callback(), libcopp_internal_api_set::set_callee(), and coroutine_context::start().
|
protectedinherited |
callee runtime context
Definition at line 64 of file coroutine_context.h.
Referenced by coroutine_context::start().
|
protectedinherited |
Definition at line 61 of file coroutine_context.h.
Referenced by libcopp_internal_api_set::coroutine_context_callback(), and libcopp_internal_api_set::set_caller().
|
privateinherited |
coroutine return code
Definition at line 105 of file coroutine_context_base.h.
Referenced by libcopp_internal_api_set::coroutine_context_callback().
|
privateinherited |
coroutine runner
Definition at line 107 of file coroutine_context_base.h.
|
privateinherited |
Definition at line 108 of file coroutine_context_base.h.
|
private |
stack allocator
Definition at line 195 of file coroutine_context_container.h.
Referenced by coroutine_context_container< TALLOC >::use_count().
|
privateinherited |
flags
Definition at line 106 of file coroutine_context_base.h.
|
privateinherited |
Definition at line 104 of file coroutine_context_base.h.
|
privateinherited |
Definition at line 114 of file coroutine_context_base.h.
Referenced by coroutine_context::start().