libcopp  2.2.0
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends
coroutine_context Class Reference

base type of all stackful coroutine context More...

#include <coroutine_context.h>

Inheritance diagram for coroutine_context:
Inheritance graph
Collaboration diagram for coroutine_context:
Collaboration graph

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_baseget_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_contextoperator= (const coroutine_context &)=delete
 
 coroutine_context (const coroutine_context &&)=delete
 
coroutine_contextoperator= (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
 

Detailed Description

base type of all stackful coroutine context

Definition at line 26 of file coroutine_context.h.

Member Typedef Documentation

◆ callback_t

Definition at line 35 of file coroutine_context.h.

◆ callback_type

Definition at line 29 of file coroutine_context.h.

◆ flag_t

Definition at line 37 of file coroutine_context.h.

◆ flag_type

Definition at line 31 of file coroutine_context.h.

◆ ptr_t

Definition at line 34 of file coroutine_context.h.

◆ ptr_type

using coroutine_context::ptr_type = LIBCOPP_COPP_NAMESPACE_ID::util::intrusive_ptr<coroutine_context>

Definition at line 28 of file coroutine_context.h.

◆ status_t

Definition at line 36 of file coroutine_context.h.

◆ status_type

Definition at line 30 of file coroutine_context.h.

Constructor & Destructor Documentation

◆ coroutine_context() [1/3]

LIBCOPP_COPP_API coroutine_context::coroutine_context ( )
protected

callee stack context

Definition at line 271 of file coroutine_context.cpp.

◆ ~coroutine_context()

LIBCOPP_COPP_API coroutine_context::~coroutine_context ( )

Definition at line 282 of file coroutine_context.cpp.

◆ coroutine_context() [2/3]

coroutine_context::coroutine_context ( const coroutine_context )
privatedelete

◆ coroutine_context() [3/3]

coroutine_context::coroutine_context ( const coroutine_context &&  )
privatedelete

Member Function Documentation

◆ align_address_size()

static size_t coroutine_context_base::align_address_size ( size_t  sz)
inlinestaticinherited

◆ align_private_data_size()

static UTIL_FORCEINLINE size_t coroutine_context_base::align_private_data_size ( size_t  sz)
inlinestaticinherited

◆ align_stack_size()

static size_t coroutine_context_base::align_stack_size ( size_t  sz)
inlinestaticinherited

Definition at line 227 of file coroutine_context_base.h.

References COROUTINE_CONTEXT_STACK_ALIGN_UNIT_SIZE.

◆ check_flags()

LIBCOPP_COPP_API bool coroutine_context_base::check_flags ( int  flags) const
inherited

check flags

Parameters
flagsflags to be checked
Returns
true if flags any flags is true

Definition at line 98 of file coroutine_context.cpp.

Referenced by this_coroutine::get_coroutine(), and start().

◆ create() [1/2]

LIBCOPP_COPP_API int coroutine_context::create ( coroutine_context p,
callback_type &&  runner,
const stack_context callee_stack,
size_t  coroutine_size,
size_t  private_buffer_size 
)
static

create coroutine context at stack context callee_

Parameters
runnerrunner
callee_stackstack context
coroutine_sizesize of coroutine object
private_buffer_sizesize of private buffer
Returns
COPP_EC_SUCCESS or error code

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().

◆ create() [2/2]

template<typename TRunner >
static LIBCOPP_COPP_API_HEAD_ONLY int coroutine_context::create ( coroutine_context p,
TRunner *  runner,
const stack_context callee_stack,
size_t  coroutine_size,
size_t  private_buffer_size 
)
inlinestatic

Definition at line 92 of file coroutine_context.h.

References create().

◆ get_private_buffer()

UTIL_FORCEINLINE void* coroutine_context_base::get_private_buffer ( ) const
inlineinherited

get private buffer(raw pointer)

Definition at line 195 of file coroutine_context_base.h.

References coroutine_context_base::priv_data_.

◆ get_private_buffer_size()

UTIL_FORCEINLINE size_t coroutine_context_base::get_private_buffer_size ( ) const
inlineinherited

get private buffer size

Definition at line 200 of file coroutine_context_base.h.

References coroutine_context_base::private_buffer_size_.

◆ get_ret_code()

UTIL_FORCEINLINE int coroutine_context_base::get_ret_code ( ) const
inlineinherited

get runner return code

Returns

Definition at line 184 of file coroutine_context_base.h.

References coroutine_context_base::runner_ret_code_.

◆ get_runner()

UTIL_FORCEINLINE const std::function<int(void *)>& coroutine_context_base::get_runner ( ) const
inlineinherited

get runner of this coroutine context (const)

Returns
nullptr of pointer of runner

Definition at line 178 of file coroutine_context_base.h.

References coroutine_context_base::runner_.

◆ get_this_coroutine_base()

LIBCOPP_COPP_API coroutine_context_base * coroutine_context_base::get_this_coroutine_base ( )
staticinherited

get current coroutine

See also
detail::coroutine_context_base
Returns
pointer of current coroutine, if not in coroutine, return nullptr

Definition at line 123 of file coroutine_context.cpp.

References detail::get_this_coroutine_context().

◆ is_finished()

LIBCOPP_COPP_API bool coroutine_context_base::is_finished ( ) const
inherited

get runner return code

Returns
true if coroutine has run and finished

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_.

◆ operator=() [1/2]

coroutine_context& coroutine_context::operator= ( const coroutine_context &&  )
privatedelete

◆ operator=() [2/2]

coroutine_context& coroutine_context::operator= ( const coroutine_context )
privatedelete

◆ resume()

LIBCOPP_COPP_API int coroutine_context::resume ( void *  priv_data = nullptr)

resume coroutine

Parameters
priv_dataprivate data, will be passed to runner operator() or return to yield
Exceptions
ifexception is enabled, it will throw all unhandled exception after resumed
Returns
COPP_EC_SUCCESS or error code

Definition at line 415 of file coroutine_context.cpp.

References start().

◆ run_and_recv_retcode()

UTIL_FORCEINLINE void coroutine_context_base::run_and_recv_retcode ( void *  priv_data)
inlineprotectedinherited

◆ set_flags()

LIBCOPP_COPP_API bool coroutine_context_base::set_flags ( int  flags)
inherited

set all flags to true

Parameters
flags(flags & EN_CFT_MASK) must be 0
Returns
true if flags is available, or return false

Definition at line 80 of file coroutine_context.cpp.

◆ set_runner()

LIBCOPP_COPP_API int coroutine_context_base::set_runner ( callback_type &&  runner)
inherited

◆ set_this_coroutine_base()

LIBCOPP_COPP_API void coroutine_context_base::set_this_coroutine_base ( coroutine_context_base ctx)
staticinherited

set current coroutine

See also
detail::coroutine_context_base
Parameters
ctxpointer of current coroutine, if not in coroutine, set nullptr

Definition at line 127 of file coroutine_context.cpp.

References detail::set_this_coroutine_context().

◆ start()

LIBCOPP_COPP_API int coroutine_context::start ( void *  priv_data = nullptr)

◆ unset_flags()

LIBCOPP_COPP_API bool coroutine_context_base::unset_flags ( int  flags)
inherited

set all flags to false

Parameters
flags(flags & EN_CFT_MASK) must be 0
Returns
true if flags is available, or return false

Definition at line 89 of file coroutine_context.cpp.

◆ yield()

LIBCOPP_COPP_API int coroutine_context::yield ( void **  priv_data = nullptr)

Friends And Related Function Documentation

◆ libcopp_internal_api_set

friend struct libcopp_internal_api_set
friend

Definition at line 56 of file coroutine_context.h.

Field Documentation

◆ callee_

fcontext::fcontext_t coroutine_context::callee_
protected

◆ callee_stack_

stack_context coroutine_context::callee_stack_
protected

callee runtime context

Definition at line 62 of file coroutine_context.h.

Referenced by start().

◆ caller_

fcontext::fcontext_t coroutine_context::caller_
protected

◆ flags_

int coroutine_context_base::flags_
private

coroutine return code

Definition at line 105 of file coroutine_context_base.h.

Referenced by libcopp_internal_api_set::coroutine_context_callback().

◆ priv_data_

void* coroutine_context_base::priv_data_
private

coroutine runner

Definition at line 107 of file coroutine_context_base.h.

◆ private_buffer_size_

size_t coroutine_context_base::private_buffer_size_
private

Definition at line 108 of file coroutine_context_base.h.

◆ runner_

callback_type coroutine_context_base::runner_
private

flags

Definition at line 106 of file coroutine_context_base.h.

◆ runner_ret_code_

int coroutine_context_base::runner_ret_code_
private

Definition at line 104 of file coroutine_context_base.h.

◆ status_

LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type<int> coroutine_context_base::status_
private

Definition at line 114 of file coroutine_context_base.h.

Referenced by start().


The documentation for this class was generated from the following files: