libcopp
2.2.0
|
base type of all stackful coroutine context More...
#include <coroutine_context.h>
Data Structures | |
struct | jump_src_data_t |
Public Types | |
using | ptr_type = LIBCOPP_COPP_NAMESPACE_ID::util::intrusive_ptr< coroutine_context > |
using | callback_type = coroutine_context_base::callback_type |
using | status_type = coroutine_context_base::status_type |
using | flag_type = coroutine_context_base::flag_type |
using | ptr_t = ptr_type |
using | callback_t = callback_type |
using | status_t = status_type |
using | flag_t = flag_type |
Public Member Functions | |
LIBCOPP_COPP_API | ~coroutine_context () |
LIBCOPP_COPP_API int | start (void *priv_data=nullptr) |
start coroutine More... | |
LIBCOPP_COPP_API int | resume (void *priv_data=nullptr) |
resume coroutine More... | |
LIBCOPP_COPP_API int | yield (void **priv_data=nullptr) LIBCOPP_MACRO_NOEXCEPT |
yield coroutine More... | |
LIBCOPP_COPP_API bool | set_flags (int flags) LIBCOPP_MACRO_NOEXCEPT |
set all flags to true More... | |
LIBCOPP_COPP_API bool | unset_flags (int flags) LIBCOPP_MACRO_NOEXCEPT |
set all flags to false More... | |
LIBCOPP_COPP_API bool | check_flags (int flags) const LIBCOPP_MACRO_NOEXCEPT |
check flags More... | |
LIBCOPP_COPP_API int | set_runner (callback_type &&runner) |
set runner More... | |
UTIL_FORCEINLINE const std::function< int(void *)> & | get_runner () const LIBCOPP_MACRO_NOEXCEPT |
UTIL_FORCEINLINE int | get_ret_code () const LIBCOPP_MACRO_NOEXCEPT |
get runner return code More... | |
LIBCOPP_COPP_API bool | is_finished () const LIBCOPP_MACRO_NOEXCEPT |
get runner return code More... | |
UTIL_FORCEINLINE void * | get_private_buffer () const LIBCOPP_MACRO_NOEXCEPT |
get private buffer(raw pointer) More... | |
UTIL_FORCEINLINE size_t | get_private_buffer_size () const LIBCOPP_MACRO_NOEXCEPT |
get private buffer size More... | |
Static Public Member Functions | |
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_ More... | |
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 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 More... | |
static LIBCOPP_COPP_API void | set_this_coroutine_base (coroutine_context_base *ctx) LIBCOPP_MACRO_NOEXCEPT |
set current coroutine More... | |
Protected Member Functions | |
LIBCOPP_COPP_API | coroutine_context () LIBCOPP_MACRO_NOEXCEPT |
UTIL_FORCEINLINE void | run_and_recv_retcode (void *priv_data) |
coroutine entrance function More... | |
Protected Attributes | |
fcontext::fcontext_t | caller_ |
fcontext::fcontext_t | callee_ |
stack_context | callee_stack_ |
Private Member Functions | |
coroutine_context (const coroutine_context &)=delete | |
coroutine_context & | operator= (const coroutine_context &)=delete |
coroutine_context (const coroutine_context &&)=delete | |
coroutine_context & | operator= (const coroutine_context &&)=delete |
Private Attributes | |
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< int > | status_ |
Friends | |
struct | libcopp_internal_api_set |
base type of all stackful coroutine context
Definition at line 26 of file coroutine_context.h.
Definition at line 35 of file coroutine_context.h.
Definition at line 29 of file coroutine_context.h.
using coroutine_context::flag_t = flag_type |
Definition at line 37 of file coroutine_context.h.
Definition at line 31 of file coroutine_context.h.
using coroutine_context::ptr_t = ptr_type |
Definition at line 34 of file coroutine_context.h.
using coroutine_context::ptr_type = LIBCOPP_COPP_NAMESPACE_ID::util::intrusive_ptr<coroutine_context> |
Definition at line 28 of file coroutine_context.h.
Definition at line 36 of file coroutine_context.h.
Definition at line 30 of file coroutine_context.h.
|
protected |
callee stack context
Definition at line 271 of file coroutine_context.cpp.
LIBCOPP_COPP_API coroutine_context::~coroutine_context | ( | ) |
Definition at line 282 of file coroutine_context.cpp.
|
privatedelete |
|
privatedelete |
|
inlinestaticinherited |
Definition at line 219 of file coroutine_context_base.h.
References COROUTINE_CONTEXT_BASE_ALIGN_UNIT_SIZE.
Referenced by coroutine_context_container< TALLOC >::create().
|
inlinestaticinherited |
Definition at line 203 of file coroutine_context_base.h.
References COROUTINE_CONTEXT_BASE_ALIGN_UNIT_SIZE.
Referenced by coroutine_context_container< TALLOC >::create().
|
inlinestaticinherited |
Definition at line 227 of file coroutine_context_base.h.
References COROUTINE_CONTEXT_STACK_ALIGN_UNIT_SIZE.
|
inherited |
check flags
flags | flags to be checked |
Definition at line 98 of file coroutine_context.cpp.
Referenced by this_coroutine::get_coroutine(), and start().
|
static |
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 create().
|
inlinestatic |
Definition at line 92 of file coroutine_context.h.
References create().
|
inlineinherited |
get private buffer(raw pointer)
Definition at line 195 of file coroutine_context_base.h.
References coroutine_context_base::priv_data_.
|
inlineinherited |
get private buffer size
Definition at line 200 of file coroutine_context_base.h.
References coroutine_context_base::private_buffer_size_.
|
inlineinherited |
get runner return code
Definition at line 184 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, util::lock::memory_order_acquire, and coroutine_context_base::status_.
|
privatedelete |
|
privatedelete |
LIBCOPP_COPP_API int coroutine_context::resume | ( | void * | priv_data = nullptr | ) |
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 415 of file coroutine_context.cpp.
References 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, util::lock::memory_order_acq_rel, util::lock::memory_order_acquire, 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().
LIBCOPP_COPP_API int coroutine_context::start | ( | void * | priv_data = nullptr | ) |
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 347 of file coroutine_context.cpp.
References callee_, callee_stack_, coroutine_context_base::check_flags(), COPP_EC_CAN_NOT_USE_CROSS_FCONTEXT_AND_FIBER, COPP_EC_IS_RUNNING, COPP_EC_NOT_INITED, COPP_EC_NOT_READY, COPP_EC_SUCCESS, COPP_UNLIKELY_IF, 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, this_coroutine::get_coroutine(), detail::get_this_coroutine_context(), jump_to(), util::lock::memory_order_acq_rel, util::lock::memory_order_acquire, util::lock::memory_order_release, coroutine_context::jump_src_data_t::priv_data, status_, util::swap(), and coroutine_context::jump_src_data_t::to_co.
Referenced by resume().
|
inherited |
set all flags to false
flags | (flags & EN_CFT_MASK) must be 0 |
Definition at line 89 of file coroutine_context.cpp.
LIBCOPP_COPP_API int coroutine_context::yield | ( | void ** | priv_data = nullptr | ) |
yield coroutine
priv_data | private data, if not nullptr, will get the value from start(priv_data) or resume(priv_data) |
Definition at line 422 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(), util::lock::memory_order_acq_rel, util::lock::memory_order_acquire, 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 56 of file coroutine_context.h.
|
protected |
caller runtime context
Definition at line 60 of file coroutine_context.h.
Referenced by libcopp_internal_api_set::coroutine_context_callback(), libcopp_internal_api_set::set_callee(), and start().
|
protected |
|
protected |
Definition at line 59 of file coroutine_context.h.
Referenced by libcopp_internal_api_set::coroutine_context_callback(), and libcopp_internal_api_set::set_caller().
|
private |
coroutine return code
Definition at line 105 of file coroutine_context_base.h.
Referenced by libcopp_internal_api_set::coroutine_context_callback().
|
private |
coroutine runner
Definition at line 107 of file coroutine_context_base.h.
|
private |
Definition at line 108 of file coroutine_context_base.h.
|
private |
flags
Definition at line 106 of file coroutine_context_base.h.
|
private |
Definition at line 104 of file coroutine_context_base.h.
|
private |
Definition at line 114 of file coroutine_context_base.h.
Referenced by start().