libcopp  2.2.0
Data Structures | Namespaces | Functions | Variables
coroutine_context.cpp File Reference
#include <libcopp/utils/config/libcopp_build_features.h>
#include <libcopp/utils/errno.h>
#include <libcopp/utils/std/explicit_declare.h>
#include <libcopp/coroutine/coroutine_context.h>
#include <libcopp/utils/config/stl_include_prefix.h>
#include <pthread.h>
#include <assert.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <libcopp/utils/config/stl_include_suffix.h>
Include dependency graph for coroutine_context.cpp:

Go to the source code of this file.

Data Structures

struct  libcopp_internal_api_set
 

Namespaces

 detail
 
 this_coroutine
 

Functions

static void detail::init_pthread_this_coroutine_context ()
 
static void detail::set_this_coroutine_context (coroutine_context_base *p)
 
static coroutine_context_basedetail::get_this_coroutine_context ()
 
static void jump_to (fcontext::fcontext_t &to_fctx, EXPLICIT_UNUSED_ATTR stack_context &from_sctx, EXPLICIT_UNUSED_ATTR stack_context &to_sctx, libcopp_internal_api_set::jump_src_data_t &jump_transfer) LIBCOPP_MACRO_NOEXCEPT
 call platform jump to asm instruction More...
 
LIBCOPP_COPP_API coroutine_contextthis_coroutine::get_coroutine () LIBCOPP_MACRO_NOEXCEPT
 get current coroutine More...
 
LIBCOPP_COPP_API int this_coroutine::yield (void **priv_data=nullptr) LIBCOPP_MACRO_NOEXCEPT
 yield current coroutine More...
 

Variables

static pthread_once_t detail::gt_coroutine_init_once = PTHREAD_ONCE_INIT
 
static pthread_key_t detail::gt_coroutine_tls_key
 

Function Documentation

◆ jump_to()

static void jump_to ( fcontext::fcontext_t to_fctx,
EXPLICIT_UNUSED_ATTR stack_context from_sctx,
EXPLICIT_UNUSED_ATTR stack_context to_sctx,
libcopp_internal_api_set::jump_src_data_t jump_transfer 
)
inlinestatic

call platform jump to asm instruction

Parameters
to_fctxjump to function context
from_sctxjump from stack context(only used for save segment stack)
to_sctxjump to stack context(only used for set segment stack)
jump_transferjump data

save from_co's fcontext and switch status we should use from_co in transfer_t, because it may not jump from jump_transfer.to_co

if we jump sequence is A->B->C->A.resume(), and if this call is A->B, then jump_src->from_co = C, jump_src->to_co = A, jump_transfer.from_co = A, jump_transfer.to_co = B and now we should save the callee of C and set the caller of A = C

if we jump sequence is A->B.yield()->A, and if this call is A->B, then jump_src->from_co = B, jump_src->to_co = nullptr, jump_transfer.from_co = A, jump_transfer.to_co = B and now we should save the callee of B and should change the caller of A

Definition at line 219 of file coroutine_context.cpp.

References fcontext::copp_jump_fcontext_v2(), coroutine_context::jump_src_data_t::from_co, coroutine_context::jump_src_data_t::priv_data, libcopp_internal_api_set::set_callee(), libcopp_internal_api_set::set_caller(), detail::set_this_coroutine_context(), and coroutine_context::jump_src_data_t::to_co.

Referenced by coroutine_context::start(), and coroutine_context::yield().