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

base type of all coroutine context More...

#include <coroutine_context.h>

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

Data Structures

struct  flag_t
 
struct  jump_src_data_t
 
struct  status_t
 status of safe coroutine context base More...
 

Public Types

typedef std::intrusive_ptr< coroutine_contextptr_t
 
typedef std::function< int(void *)> callback_t
 

Public Member Functions

 ~coroutine_context ()
 
int start (void *priv_data=UTIL_CONFIG_NULLPTR)
 start coroutine More...
 
int resume (void *priv_data=UTIL_CONFIG_NULLPTR)
 resume coroutine More...
 
int yield (void **priv_data=UTIL_CONFIG_NULLPTR)
 yield coroutine More...
 
bool set_flags (int flags)
 set all flags to true More...
 
bool unset_flags (int flags)
 set all flags to false More...
 
bool check_flags (int flags) const
 check flags More...
 
int set_runner (const callback_t &runner)
 set runner More...
 
const std::function< int(void *)> & get_runner () const UTIL_CONFIG_NOEXCEPT
 
int get_ret_code () const UTIL_CONFIG_NOEXCEPT
 get runner return code More...
 
bool is_finished () const UTIL_CONFIG_NOEXCEPT
 get runner return code More...
 
void * get_private_buffer () const UTIL_CONFIG_NOEXCEPT
 get private buffer(raw pointer) More...
 
size_t get_private_buffer_size () const UTIL_CONFIG_NOEXCEPT
 get private buffer size More...
 

Static Public Member Functions

static int create (coroutine_context *p, callback_t &runner, const stack_context &callee_stack, size_t coroutine_size, size_t private_buffer_size) UTIL_CONFIG_NOEXCEPT
 create coroutine context at stack context callee_ More...
 
template<typename TRunner >
static int create (coroutine_context *p, TRunner *runner, const stack_context &callee_stack, size_t coroutine_size, size_t private_buffer_size) UTIL_CONFIG_NOEXCEPT
 
static size_t align_private_data_size (size_t sz)
 
static size_t align_address_size (size_t sz)
 

Protected Member Functions

 coroutine_context () UTIL_CONFIG_NOEXCEPT
 
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 Attributes

int runner_ret_code_
 
int flags_
 
callback_t runner_
 
void * priv_data_
 
size_t private_buffer_size_
 
util::lock::atomic_int_type< int > status_
 

Friends

struct libcopp_inner_api_helper
 

Detailed Description

base type of all coroutine context

Definition at line 64 of file coroutine_context.h.

Member Typedef Documentation

typedef std::function<int(void *)> copp::coroutine_context::callback_t

Definition at line 67 of file coroutine_context.h.

Definition at line 66 of file coroutine_context.h.

Constructor & Destructor Documentation

copp::coroutine_context::coroutine_context ( )
protected

status

Definition at line 233 of file coroutine_context.cpp.

copp::coroutine_context::~coroutine_context ( )

Definition at line 247 of file coroutine_context.cpp.

Member Function Documentation

static size_t copp::coroutine_context::align_address_size ( size_t  sz)
inlinestatic
static size_t copp::coroutine_context::align_private_data_size ( size_t  sz)
inlinestatic
bool copp::coroutine_context::check_flags ( int  flags) const

check flags

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

Definition at line 411 of file coroutine_context.cpp.

References set_runner().

Referenced by cotask::impl::task_impl::this_task().

int copp::coroutine_context::create ( coroutine_context p,
callback_t 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 249 of file coroutine_context.cpp.

References copp::COPP_EC_ARGS_ERROR, copp::COPP_EC_FCONTEXT_MAKE_FAILED, copp::COPP_EC_SUCCESS, COPP_MACRO_STD_MOVE, copp::fcontext::copp_make_fcontext(), and copp::libcopp_inner_api_helper::coroutine_context_callback().

Referenced by CASE_TEST(), and copp::coroutine_context_container< TALLOC >::create().

template<typename TRunner >
static int copp::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 140 of file coroutine_context.h.

References copp::this_coroutine::yield().

void* copp::coroutine_context::get_private_buffer ( ) const
inline

get private buffer(raw pointer)

Definition at line 232 of file coroutine_context.h.

Referenced by cotask::impl::task_impl::this_task().

size_t copp::coroutine_context::get_private_buffer_size ( ) const
inline

get private buffer size

Definition at line 237 of file coroutine_context.h.

int copp::coroutine_context::get_ret_code ( ) const
inline

get runner return code

Returns

Definition at line 221 of file coroutine_context.h.

const std::function<int(void *)>& copp::coroutine_context::get_runner ( ) const
inline

get runner of this coroutine context (const)

Returns
NULL of pointer of runner

Definition at line 215 of file coroutine_context.h.

bool copp::coroutine_context::is_finished ( ) const

get runner return code

Returns
true if coroutine has run and finished

Definition at line 432 of file coroutine_context.cpp.

References util::lock::memory_order_acquire.

int copp::coroutine_context::resume ( void *  priv_data = UTIL_CONFIG_NULLPTR)

resume coroutine

Parameters
priv_dataprivate data, will be passed to runner operator() or return to yield
Returns
COPP_EC_SUCCESS or error code

Definition at line 347 of file coroutine_context.cpp.

void copp::coroutine_context::run_and_recv_retcode ( void *  priv_data)
inlineprotected

coroutine entrance function

Definition at line 193 of file coroutine_context.h.

Referenced by copp::libcopp_inner_api_helper::coroutine_context_callback().

bool copp::coroutine_context::set_flags ( int  flags)

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 393 of file coroutine_context.cpp.

int copp::coroutine_context::set_runner ( const callback_t runner)

set runner

Parameters
runner
Returns
COPP_EC_SUCCESS or error code

Definition at line 416 of file coroutine_context.cpp.

References copp::COPP_EC_ALREADY_INITED, copp::COPP_EC_ARGS_ERROR, copp::COPP_EC_SUCCESS, COPP_MACRO_STD_MOVE, util::lock::memory_order_acq_rel, and util::lock::memory_order_acquire.

Referenced by check_flags().

int copp::coroutine_context::start ( void *  priv_data = UTIL_CONFIG_NULLPTR)
bool copp::coroutine_context::unset_flags ( int  flags)

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 402 of file coroutine_context.cpp.

int copp::coroutine_context::yield ( void **  priv_data = UTIL_CONFIG_NULLPTR)

Friends And Related Function Documentation

friend struct libcopp_inner_api_helper
friend

Definition at line 103 of file coroutine_context.h.

Field Documentation

fcontext::fcontext_t copp::coroutine_context::callee_
protected
stack_context copp::coroutine_context::callee_stack_
protected

callee runtime context

Definition at line 109 of file coroutine_context.h.

Referenced by copp::libcopp_inner_api_helper::set_callee().

fcontext::fcontext_t copp::coroutine_context::caller_
protected
int copp::coroutine_context::flags_
private

coroutine return code

Definition at line 92 of file coroutine_context.h.

Referenced by copp::libcopp_inner_api_helper::coroutine_context_callback().

void* copp::coroutine_context::priv_data_
private

coroutine runner

Definition at line 94 of file coroutine_context.h.

size_t copp::coroutine_context::private_buffer_size_
private

Definition at line 95 of file coroutine_context.h.

callback_t copp::coroutine_context::runner_
private

flags

Definition at line 93 of file coroutine_context.h.

int copp::coroutine_context::runner_ret_code_
private

Definition at line 91 of file coroutine_context.h.

util::lock::atomic_int_type<int> copp::coroutine_context::status_
private

callee stack context

Definition at line 118 of file coroutine_context.h.


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