libcopp  1.2.1
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | Friends
cotask::task< TCO_MACRO, TTASK_MACRO > Class Template Reference

#include <task.h>

Inheritance diagram for cotask::task< TCO_MACRO, TTASK_MACRO >:
Inheritance graph
Collaboration diagram for cotask::task< TCO_MACRO, TTASK_MACRO >:
Collaboration graph

Data Structures

struct  task_group
 

Public Types

typedef task< TCO_MACRO, TTASK_MACRO > self_t
 
typedef std::intrusive_ptr< self_tptr_t
 
typedef TCO_MACRO macro_coroutine_t
 
typedef TTASK_MACRO macro_task_t
 
typedef macro_coroutine_t::coroutine_t coroutine_t
 
typedef macro_coroutine_t::stack_allocator_t stack_allocator_t
 
typedef macro_task_t::id_t id_t
 
typedef macro_task_t::id_allocator_t id_allocator_t
 

Public Member Functions

 task (size_t stack_sz)
 constuctor More...
 
ptr_t next (ptr_t next_task, void *priv_data=UTIL_CONFIG_NULLPTR)
 add next task to run when task finished More...
 
template<typename Ty >
ptr_t next (const Ty &functor, void *priv_data=UTIL_CONFIG_NULLPTR, size_t stack_size=0, size_t private_buffer_size=0)
 create next task with functor More...
 
template<typename Ty >
ptr_t next (const Ty &functor, typename coroutine_t::allocator_type &alloc, void *priv_data=UTIL_CONFIG_NULLPTR, size_t stack_size=0, size_t private_buffer_size=0)
 
template<typename Ty >
ptr_t next (Ty(*func)(void *), void *priv_data=UTIL_CONFIG_NULLPTR, size_t stack_size=0, size_t private_buffer_size=0)
 create next task with function More...
 
template<typename Ty >
ptr_t next (Ty(*func)(void *), typename coroutine_t::allocator_type &alloc, void *priv_data=UTIL_CONFIG_NULLPTR, size_t stack_size=0, size_t private_buffer_size=0)
 
template<typename Ty , typename TInst >
ptr_t next (Ty(TInst::*func), TInst *instance, void *priv_data=UTIL_CONFIG_NULLPTR, size_t stack_size=0, size_t private_buffer_size=0)
 create next task with function More...
 
template<typename Ty , typename TInst >
ptr_t next (Ty(TInst::*func), TInst *instance, typename coroutine_t::allocator_type &alloc, void *priv_data=UTIL_CONFIG_NULLPTR, size_t stack_size=0, size_t private_buffer_size=0)
 
int await (ptr_t wait_task)
 await another cotask to finish More...
 
template<typename TTask >
int await (TTask *wait_task)
 
ptr_t then (ptr_t next_task, void *priv_data=UTIL_CONFIG_NULLPTR)
 add task to run when task finished More...
 
template<typename Ty >
ptr_t then (const Ty &functor, typename coroutine_t::allocator_type &alloc, void *priv_data=UTIL_CONFIG_NULLPTR, size_t stack_size=0, size_t private_buffer_size=0)
 create next task with functor using the same allocator and private buffer size as this task More...
 
template<typename Ty >
ptr_t then (Ty(*func)(void *), void *priv_data=UTIL_CONFIG_NULLPTR)
 
virtual ~task ()
 
coroutine_t::ptr_t & get_coroutine_context () UTIL_CONFIG_NOEXCEPT
 
const coroutine_t::ptr_t & get_coroutine_context () const UTIL_CONFIG_NOEXCEPT
 
id_t get_id () const UTIL_CONFIG_NOEXCEPT
 
virtual int get_ret_code () const UTIL_CONFIG_OVERRIDE
 
virtual int start (void *priv_data, EN_TASK_STATUS expected_status=EN_TS_CREATED) UTIL_CONFIG_OVERRIDE
 
virtual int resume (void *priv_data, EN_TASK_STATUS expected_status=EN_TS_WAITING) UTIL_CONFIG_OVERRIDE
 
virtual int yield (void **priv_data) UTIL_CONFIG_OVERRIDE
 
virtual int cancel (void *priv_data) UTIL_CONFIG_OVERRIDE
 
virtual int kill (enum EN_TASK_STATUS status, void *priv_data) UTIL_CONFIG_OVERRIDE
 
virtual bool is_completed () const UTIL_CONFIG_NOEXCEPT UTIL_CONFIG_OVERRIDE
 
void * get_private_buffer ()
 
size_t get_private_buffer_size ()
 
size_t use_count () const
 
EN_TASK_STATUS get_status () const UTIL_CONFIG_NOEXCEPT
 
virtual bool is_canceled () const UTIL_CONFIG_NOEXCEPT
 
virtual bool is_faulted () const UTIL_CONFIG_NOEXCEPT
 
virtual bool is_timeout () const UTIL_CONFIG_NOEXCEPT
 
bool is_exiting () const UTIL_CONFIG_NOEXCEPT
 check if a cotask is exiting More...
 
int start ()
 
int resume ()
 
int yield ()
 
int cancel ()
 
int kill (void *priv_data)
 
int kill (enum EN_TASK_STATUS status)
 
int kill ()
 
virtual int on_finished ()
 
action_ptr_t get_raw_action () const UTIL_CONFIG_NOEXCEPT
 get raw action pointer More...
 

Static Public Member Functions

template<typename TAct , typename Ty >
static ptr_t create_with_delegate (const Ty &callable, typename coroutine_t::allocator_type &alloc, size_t stack_size=0, size_t private_buffer_size=0)
 create task with functor More...
 
template<typename Ty >
static ptr_t create (const Ty &functor, size_t stack_size=0, size_t private_buffer_size=0)
 create task with functor More...
 
template<typename Ty >
static ptr_t create (const Ty &functor, typename coroutine_t::allocator_type &alloc, size_t stack_size=0, size_t private_buffer_size=0)
 
template<typename Ty >
static ptr_t create (Ty(*func)(void *), typename coroutine_t::allocator_type &alloc, size_t stack_size=0, size_t private_buffer_size=0)
 create task with function More...
 
template<typename Ty >
static ptr_t create (Ty(*func)(void *), size_t stack_size=0, size_t private_buffer_size=0)
 
template<typename Ty , typename TInst >
static ptr_t create (Ty(TInst::*func), TInst *instance, typename coroutine_t::allocator_type &alloc, size_t stack_size=0, size_t private_buffer_size=0)
 create task with function More...
 
template<typename Ty , typename TInst >
static ptr_t create (Ty(TInst::*func), TInst *instance, size_t stack_size=0, size_t private_buffer_size=0)
 
static self_tthis_task ()
 
static void * add_buffer_offset (void *in, size_t off)
 
static void * sub_buffer_offset (void *in, size_t off)
 

Protected Member Functions

void _set_action (action_ptr_t action)
 
action_ptr_t _get_action ()
 
bool _cas_status (EN_TASK_STATUS &expected, EN_TASK_STATUS desired)
 

Protected Attributes

void * finish_priv_data_
 

Private Types

typedef impl::task_impl::action_ptr_t action_ptr_t
 

Private Member Functions

 task (const task &) UTIL_CONFIG_DELETED_FUNCTION
 
void active_next_tasks ()
 
int _notify_finished (void *priv_data)
 

Private Attributes

id_t id_
 
size_t stack_size_
 
coroutine_t::ptr_t coroutine_obj_
 
task_group next_list_
 
void(* action_destroy_fn_ )(void *)
 
util::lock::atomic_int_type< size_t > ref_count_
 
util::lock::spin_lock inner_action_lock_
 

Friends

void intrusive_ptr_add_ref (self_t *p)
 
void intrusive_ptr_release (self_t *p)
 

Detailed Description

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
class cotask::task< TCO_MACRO, TTASK_MACRO >

Definition at line 28 of file task.h.

Member Typedef Documentation

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
typedef impl::task_impl::action_ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::action_ptr_t
private

Definition at line 47 of file task.h.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
typedef macro_coroutine_t::coroutine_t cotask::task< TCO_MACRO, TTASK_MACRO >::coroutine_t

Definition at line 35 of file task.h.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
typedef macro_task_t::id_allocator_t cotask::task< TCO_MACRO, TTASK_MACRO >::id_allocator_t

Definition at line 39 of file task.h.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
typedef macro_task_t::id_t cotask::task< TCO_MACRO, TTASK_MACRO >::id_t

Definition at line 38 of file task.h.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
typedef TCO_MACRO cotask::task< TCO_MACRO, TTASK_MACRO >::macro_coroutine_t

Definition at line 32 of file task.h.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
typedef TTASK_MACRO cotask::task< TCO_MACRO, TTASK_MACRO >::macro_task_t

Definition at line 33 of file task.h.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
typedef std::intrusive_ptr<self_t> cotask::task< TCO_MACRO, TTASK_MACRO >::ptr_t

Definition at line 31 of file task.h.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
typedef task<TCO_MACRO, TTASK_MACRO> cotask::task< TCO_MACRO, TTASK_MACRO >::self_t

Definition at line 30 of file task.h.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
typedef macro_coroutine_t::stack_allocator_t cotask::task< TCO_MACRO, TTASK_MACRO >::stack_allocator_t

Definition at line 36 of file task.h.

Constructor & Destructor Documentation

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
cotask::task< TCO_MACRO, TTASK_MACRO >::task ( size_t  stack_sz)
inline
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
virtual cotask::task< TCO_MACRO, TTASK_MACRO >::~task ( )
inlinevirtual
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
cotask::task< TCO_MACRO, TTASK_MACRO >::task ( const task< TCO_MACRO, TTASK_MACRO > &  )
private

Member Function Documentation

bool cotask::impl::task_impl::_cas_status ( EN_TASK_STATUS expected,
EN_TASK_STATUS  desired 
)
protectedinherited
task_impl::action_ptr_t cotask::impl::task_impl::_get_action ( )
protectedinherited
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
int cotask::task< TCO_MACRO, TTASK_MACRO >::_notify_finished ( void *  priv_data)
inlineprivate
void cotask::impl::task_impl::_set_action ( action_ptr_t  action)
protectedinherited
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
void cotask::task< TCO_MACRO, TTASK_MACRO >::active_next_tasks ( )
inlineprivate
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
static void* cotask::task< TCO_MACRO, TTASK_MACRO >::add_buffer_offset ( void *  in,
size_t  off 
)
inlinestatic

Definition at line 589 of file task.h.

Referenced by cotask::task< TCO_MACRO, TTASK_MACRO >::get_private_buffer().

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
int cotask::task< TCO_MACRO, TTASK_MACRO >::await ( ptr_t  wait_task)
inline

await another cotask to finish

Note
please not to make tasks refer to each other. [it will lead to memory leak]
[don't do that] ptr_t a = ..., b = ...; a.await(b); b.await(a);
Parameters
wait_taskwhich stack to wait for
Note
we will loop wait and ignore any resume(...) call
Returns
0 or error code

Definition at line 346 of file task.h.

References copp::COPP_EC_ARGS_ERROR, copp::COPP_EC_TASK_ADD_NEXT_FAILED, copp::COPP_EC_TASK_CAN_NOT_WAIT_SELF, copp::COPP_EC_TASK_IS_EXITING, copp::COPP_EC_TASK_NOT_IN_ACTION, std::intrusive_ptr< T >::get(), cotask::impl::task_impl::is_exiting(), cotask::task< TCO_MACRO, TTASK_MACRO >::this_task(), and cotask::impl::task_impl::yield().

Referenced by cotask::task< TCO_MACRO, TTASK_MACRO >::await().

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename TTask >
int cotask::task< TCO_MACRO, TTASK_MACRO >::await ( TTask *  wait_task)
inline

Definition at line 386 of file task.h.

References cotask::task< TCO_MACRO, TTASK_MACRO >::await().

int cotask::impl::task_impl::cancel ( )
inlineinherited
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
virtual int cotask::task< TCO_MACRO, TTASK_MACRO >::cancel ( void *  priv_data)
inlinevirtual
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename Ty >
static ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::create ( const Ty &  functor,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inlinestatic

create task with functor

Parameters
action
stack_sizestack size
private_buffer_sizebuffer size to store private data
Returns
task smart pointer

Definition at line 162 of file task.h.

Referenced by CASE_TEST(), cotask::task< TCO_MACRO, TTASK_MACRO >::create(), cotask::task< TCO_MACRO, TTASK_MACRO >::create_with_delegate(), main(), cotask::task< TCO_MACRO, TTASK_MACRO >::next(), and cotask::task< TCO_MACRO, TTASK_MACRO >::then().

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename Ty >
static ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::create ( const Ty &  functor,
typename coroutine_t::allocator_type &  alloc,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inlinestatic

Definition at line 168 of file task.h.

References COPP_MACRO_STD_FORWARD.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename Ty >
static ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::create ( Ty(*)(void *)  func,
typename coroutine_t::allocator_type &  alloc,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inlinestatic

create task with function

Parameters
action
stack_sizestack size
Returns
task smart pointer

Definition at line 182 of file task.h.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename Ty >
static ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::create ( Ty(*)(void *)  func,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inlinestatic

Definition at line 190 of file task.h.

References cotask::task< TCO_MACRO, TTASK_MACRO >::create().

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename Ty , typename TInst >
static ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::create ( TyTInst::*  func,
TInst *  instance,
typename coroutine_t::allocator_type &  alloc,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inlinestatic

create task with function

Parameters
action
stack_sizestack size
Returns
task smart pointer

Definition at line 202 of file task.h.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename Ty , typename TInst >
static ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::create ( TyTInst::*  func,
TInst *  instance,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inlinestatic
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename TAct , typename Ty >
static ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::create_with_delegate ( const Ty &  callable,
typename coroutine_t::allocator_type &  alloc,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inlinestatic
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
coroutine_t::ptr_t& cotask::task< TCO_MACRO, TTASK_MACRO >::get_coroutine_context ( )
inline

Definition at line 459 of file task.h.

References cotask::task< TCO_MACRO, TTASK_MACRO >::coroutine_obj_.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
const coroutine_t::ptr_t& cotask::task< TCO_MACRO, TTASK_MACRO >::get_coroutine_context ( ) const
inline

Definition at line 460 of file task.h.

References cotask::task< TCO_MACRO, TTASK_MACRO >::coroutine_obj_.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
id_t cotask::task< TCO_MACRO, TTASK_MACRO >::get_id ( ) const
inline

Definition at line 462 of file task.h.

References cotask::task< TCO_MACRO, TTASK_MACRO >::id_.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
void* cotask::task< TCO_MACRO, TTASK_MACRO >::get_private_buffer ( )
inline
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
size_t cotask::task< TCO_MACRO, TTASK_MACRO >::get_private_buffer_size ( )
inline
action_ptr_t cotask::impl::task_impl::get_raw_action ( ) const
inlineinherited

get raw action pointer

Note
this function is provided just for debug or show some information, it may return the inner type created by cotask
Returns
pointer to task_action instance

Definition at line 111 of file task_impl.h.

References cotask::impl::task_impl::_cas_status(), cotask::impl::task_impl::_get_action(), cotask::impl::task_impl::_notify_finished(), cotask::impl::task_impl::_set_action(), print_color::action, and cotask::impl::task_impl::action_.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
virtual int cotask::task< TCO_MACRO, TTASK_MACRO >::get_ret_code ( ) const
inlinevirtual
EN_TASK_STATUS cotask::impl::task_impl::get_status ( ) const
inlineinherited
bool cotask::impl::task_impl::is_canceled ( ) const
virtualinherited
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
virtual bool cotask::task< TCO_MACRO, TTASK_MACRO >::is_completed ( ) const
inlinevirtual
bool cotask::impl::task_impl::is_exiting ( ) const
inherited

check if a cotask is exiting

Note
cotask is exiting means the cotask is is_completed() or is killed. if a cotask is killed and is running, then is_completed() == false but is_exiting() == true, and after the cotask finished, is_completed() == true
Returns
return true if a cotask is exiting.

Definition at line 34 of file task_impl.cpp.

References cotask::EN_TS_DONE, and cotask::impl::task_impl::get_status().

Referenced by cotask::task< TCO_MACRO, TTASK_MACRO >::await(), cotask::impl::task_impl::get_status(), cotask::impl::task_impl::is_completed(), and cotask::task< TCO_MACRO, TTASK_MACRO >::next().

bool cotask::impl::task_impl::is_faulted ( ) const
virtualinherited
bool cotask::impl::task_impl::is_timeout ( ) const
virtualinherited
int cotask::impl::task_impl::kill ( void *  priv_data)
inlineinherited

Definition at line 89 of file task_impl.h.

References cotask::EN_TS_KILLED, and cotask::impl::task_impl::kill().

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

int cotask::impl::task_impl::kill ( enum EN_TASK_STATUS  status)
inlineinherited

Definition at line 95 of file task_impl.h.

References cotask::impl::task_impl::kill().

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

int cotask::impl::task_impl::kill ( )
inlineinherited
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
virtual int cotask::task< TCO_MACRO, TTASK_MACRO >::kill ( enum EN_TASK_STATUS  status,
void *  priv_data 
)
inlinevirtual
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::next ( ptr_t  next_task,
void *  priv_data = UTIL_CONFIG_NULLPTR 
)
inline

add next task to run when task finished

Note
please not to make tasks refer to each other. [it will lead to memory leak]
[don't do that] ptr_t a = ..., b = ...; a.next(b); b.next(a);
Parameters
next_tasknext stack
priv_datapriv_data passed to resume or start next stack
Returns
next_task if success , or self if failed

Definition at line 239 of file task.h.

References cotask::task< TCO_MACRO, TTASK_MACRO >::create(), cotask::EN_TS_CREATED, cotask::EN_TS_WAITING, std::intrusive_ptr< T >::get(), cotask::task< TCO_MACRO, TTASK_MACRO >::inner_action_lock_, cotask::task< TCO_MACRO, TTASK_MACRO >::is_completed(), cotask::impl::task_impl::is_exiting(), cotask::task< TCO_MACRO, TTASK_MACRO >::task_group::member_list_, and cotask::task< TCO_MACRO, TTASK_MACRO >::next_list_.

Referenced by cotask::task< TCO_MACRO, TTASK_MACRO >::next(), and cotask::task< TCO_MACRO, TTASK_MACRO >::then().

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename Ty >
ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::next ( const Ty &  functor,
void *  priv_data = UTIL_CONFIG_NULLPTR,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inline

create next task with functor

See also
next
Parameters
functor
priv_datapriv_data passed to start functor
stack_sizestack size
Returns
the created task if success , or self if failed

Definition at line 286 of file task.h.

References cotask::task< TCO_MACRO, TTASK_MACRO >::create(), and cotask::task< TCO_MACRO, TTASK_MACRO >::next().

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename Ty >
ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::next ( const Ty &  functor,
typename coroutine_t::allocator_type &  alloc,
void *  priv_data = UTIL_CONFIG_NULLPTR,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inline
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename Ty >
ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::next ( Ty(*)(void *)  func,
void *  priv_data = UTIL_CONFIG_NULLPTR,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inline

create next task with function

See also
next
Parameters
funcfunction
priv_datapriv_data passed to start function
stack_sizestack size
Returns
the created task if success , or self if failed

Definition at line 306 of file task.h.

References cotask::task< TCO_MACRO, TTASK_MACRO >::create(), and cotask::task< TCO_MACRO, TTASK_MACRO >::next().

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename Ty >
ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::next ( Ty(*)(void *)  func,
typename coroutine_t::allocator_type &  alloc,
void *  priv_data = UTIL_CONFIG_NULLPTR,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inline
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename Ty , typename TInst >
ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::next ( TyTInst::*  func,
TInst *  instance,
void *  priv_data = UTIL_CONFIG_NULLPTR,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inline

create next task with function

See also
next
Parameters
funcmember function
instanceinstance
priv_datapriv_data passed to start (instance->*func)(priv_data)
stack_sizestack size
Returns
the created task if success , or self if failed

Definition at line 327 of file task.h.

References cotask::task< TCO_MACRO, TTASK_MACRO >::create(), and cotask::task< TCO_MACRO, TTASK_MACRO >::next().

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename Ty , typename TInst >
ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::next ( TyTInst::*  func,
TInst *  instance,
typename coroutine_t::allocator_type &  alloc,
void *  priv_data = UTIL_CONFIG_NULLPTR,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inline
int cotask::impl::task_impl::on_finished ( )
virtualinherited
int cotask::impl::task_impl::resume ( )
inlineinherited
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
virtual int cotask::task< TCO_MACRO, TTASK_MACRO >::resume ( void *  priv_data,
EN_TASK_STATUS  expected_status = EN_TS_WAITING 
)
inlinevirtual

Implements cotask::impl::task_impl.

Definition at line 527 of file task.h.

References cotask::impl::task_impl::start().

int cotask::impl::task_impl::start ( )
inlineinherited
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
virtual int cotask::task< TCO_MACRO, TTASK_MACRO >::start ( void *  priv_data,
EN_TASK_STATUS  expected_status = EN_TS_CREATED 
)
inlinevirtual
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
static void* cotask::task< TCO_MACRO, TTASK_MACRO >::sub_buffer_offset ( void *  in,
size_t  off 
)
inlinestatic
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::then ( ptr_t  next_task,
void *  priv_data = UTIL_CONFIG_NULLPTR 
)
inline

add task to run when task finished

Note
please not to make tasks refer to each other. [it will lead to memory leak]
[don't do that] ptr_t a = ..., b = ...; a.then(b); b.then(a);
Parameters
next_taskthen stack
priv_datapriv_data passed to resume or start the stack
Returns
next_task if success , or self if failed

Definition at line 398 of file task.h.

References cotask::task< TCO_MACRO, TTASK_MACRO >::coroutine_obj_, cotask::task< TCO_MACRO, TTASK_MACRO >::create(), cotask::task< TCO_MACRO, TTASK_MACRO >::get_private_buffer_size(), cotask::task< TCO_MACRO, TTASK_MACRO >::next(), and cotask::task< TCO_MACRO, TTASK_MACRO >::stack_size_.

Referenced by cotask::task< TCO_MACRO, TTASK_MACRO >::then().

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename Ty >
ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::then ( const Ty &  functor,
typename coroutine_t::allocator_type &  alloc,
void *  priv_data = UTIL_CONFIG_NULLPTR,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inline

create next task with functor using the same allocator and private buffer size as this task

See also
next
Parameters
functor
priv_datapriv_data passed to start functor
Returns
the created task if success , or self if failed

Definition at line 419 of file task.h.

References cotask::task< TCO_MACRO, TTASK_MACRO >::coroutine_obj_, cotask::task< TCO_MACRO, TTASK_MACRO >::create(), cotask::task< TCO_MACRO, TTASK_MACRO >::get_private_buffer_size(), cotask::task< TCO_MACRO, TTASK_MACRO >::stack_size_, and cotask::task< TCO_MACRO, TTASK_MACRO >::then().

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
template<typename Ty >
ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::then ( Ty(*)(void *)  func,
void *  priv_data = UTIL_CONFIG_NULLPTR 
)
inline
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
static self_t* cotask::task< TCO_MACRO, TTASK_MACRO >::this_task ( )
inlinestatic

get current running task and convert to task object

Returns
task smart pointer

Definition at line 444 of file task.h.

References cotask::impl::task_impl::this_task().

Referenced by cotask::task< TCO_MACRO, TTASK_MACRO >::await().

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
size_t cotask::task< TCO_MACRO, TTASK_MACRO >::use_count ( ) const
inline
int cotask::impl::task_impl::yield ( )
inlineinherited
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
virtual int cotask::task< TCO_MACRO, TTASK_MACRO >::yield ( void **  priv_data)
inlinevirtual

Friends And Related Function Documentation

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
void intrusive_ptr_add_ref ( self_t p)
friend

Definition at line 677 of file task.h.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
void intrusive_ptr_release ( self_t p)
friend

Definition at line 685 of file task.h.

Field Documentation

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
void(* cotask::task< TCO_MACRO, TTASK_MACRO >::action_destroy_fn_) (void *)
private

Definition at line 750 of file task.h.

template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
coroutine_t::ptr_t cotask::task< TCO_MACRO, TTASK_MACRO >::coroutine_obj_
private
void* cotask::impl::task_impl::finish_priv_data_
protectedinherited
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
id_t cotask::task< TCO_MACRO, TTASK_MACRO >::id_
private
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
util::lock::spin_lock cotask::task< TCO_MACRO, TTASK_MACRO >::inner_action_lock_
private
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
task_group cotask::task< TCO_MACRO, TTASK_MACRO >::next_list_
private
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
util::lock::atomic_int_type<size_t> cotask::task< TCO_MACRO, TTASK_MACRO >::ref_count_
private
template<typename TCO_MACRO = macro_coroutine, typename TTASK_MACRO = macro_task>
size_t cotask::task< TCO_MACRO, TTASK_MACRO >::stack_size_
private

Definition at line 745 of file task.h.

Referenced by cotask::task< TCO_MACRO, TTASK_MACRO >::then().


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