libcopp  2.2.0
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | Friends
task< TCO_MACRO > Class Template Reference

#include <task.h>

Inheritance diagram for task< TCO_MACRO >:
Inheritance graph
Collaboration diagram for task< TCO_MACRO >:
Collaboration graph

Data Structures

struct  task_group
 

Public Types

using macro_coroutine_type = TCO_MACRO
 
using self_type = task< macro_coroutine_type >
 
using ptr_type = LIBCOPP_COPP_NAMESPACE_ID::util::intrusive_ptr< self_type >
 
using coroutine_type = typename macro_coroutine_type::coroutine_type
 
using stack_allocator_type = typename macro_coroutine_type::stack_allocator_type
 
using id_type = typename impl::task_impl::id_type
 
using id_allocator_type = typename impl::task_impl::id_allocator_type
 
using macro_coroutine_t = macro_coroutine_type
 
using self_t = self_type
 
using ptr_t = ptr_type
 
using coroutine_t = coroutine_type
 
using stack_allocator_t = stack_allocator_type
 
using id_allocator_t = id_allocator_type
 
using id_t = id_type
 

Public Member Functions

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

Static Public Member Functions

template<typename TAct , typename Ty >
static LIBCOPP_COTASK_API_HEAD_ONLY ptr_type create_with_delegate (Ty &&callable, typename coroutine_type::allocator_type &alloc, size_t stack_size=0, size_t private_buffer_size=0)
 create task with functor More...
 
template<typename Ty >
static ptr_type create (Ty &&functor, size_t stack_size=0, size_t private_buffer_size=0)
 create task with functor More...
 
template<typename Ty >
static ptr_type create (Ty &&functor, typename coroutine_type::allocator_type &alloc, size_t stack_size=0, size_t private_buffer_size=0)
 
template<typename Ty >
static ptr_type create (Ty(*func)(void *), typename coroutine_type::allocator_type &alloc, size_t stack_size=0, size_t private_buffer_size=0)
 create task with function More...
 
template<typename Ty >
static ptr_type create (Ty(*func)(void *), size_t stack_size=0, size_t private_buffer_size=0)
 
template<typename Ty , typename TInst >
static LIBCOPP_COTASK_API_HEAD_ONLY ptr_type create (Ty(TInst::*func), TInst *instance, typename coroutine_type::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_type create (Ty(TInst::*func), TInst *instance, size_t stack_size=0, size_t private_buffer_size=0)
 
template<typename Ty , typename... TParams>
static LIBCOPP_COTASK_API_HEAD_ONLY ptr_type create_with (typename coroutine_type::allocator_type &alloc, size_t stack_size, size_t private_buffer_size, TParams &&...args)
 create task with functor type and parameters More...
 
static self_typethis_task ()
 
static void * add_buffer_offset (void *in, size_t off)
 
static void * sub_buffer_offset (void *in, size_t off)
 

Protected Member Functions

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

Protected Attributes

void * finish_priv_data_
 

Private Types

using action_ptr_type = impl::task_impl::action_ptr_type
 
using action_ptr_t = action_ptr_type
 

Private Member Functions

 task (const task &)=delete
 
void active_next_tasks ()
 
int _notify_finished (void *priv_data) LIBCOPP_MACRO_NOEXCEPT
 

Private Attributes

size_t stack_size_
 
coroutine_type::ptr_type coroutine_obj_
 
task_group next_list_
 
void(* action_destroy_fn_ )(void *)
 
LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type< size_t > ref_count_
 
LIBCOPP_COPP_NAMESPACE_ID::util::lock::spin_lock inner_action_lock_
 
action_ptr_type action_
 
id_type id_
 
LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type< uint32_t > status_
 

Friends

void intrusive_ptr_add_ref (self_type *p)
 
void intrusive_ptr_release (self_type *p)
 

Detailed Description

template<typename TCO_MACRO = macro_coroutine>
class task< TCO_MACRO >

Definition at line 37 of file task.h.

Member Typedef Documentation

◆ action_ptr_t

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::action_ptr_t = action_ptr_type
private

Definition at line 61 of file task.h.

◆ action_ptr_type

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::action_ptr_type = impl::task_impl::action_ptr_type
private

Definition at line 59 of file task.h.

◆ coroutine_t

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::coroutine_t = coroutine_type

Definition at line 53 of file task.h.

◆ coroutine_type

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::coroutine_type = typename macro_coroutine_type::coroutine_type

Definition at line 43 of file task.h.

◆ id_allocator_t

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::id_allocator_t = id_allocator_type

Definition at line 55 of file task.h.

◆ id_allocator_type

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::id_allocator_type = typename impl::task_impl::id_allocator_type

Definition at line 47 of file task.h.

◆ id_t

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::id_t = id_type

Definition at line 56 of file task.h.

◆ id_type

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::id_type = typename impl::task_impl::id_type

Definition at line 46 of file task.h.

◆ macro_coroutine_t

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::macro_coroutine_t = macro_coroutine_type

Definition at line 50 of file task.h.

◆ macro_coroutine_type

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::macro_coroutine_type = TCO_MACRO

Definition at line 39 of file task.h.

◆ ptr_t

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::ptr_t = ptr_type

Definition at line 52 of file task.h.

◆ ptr_type

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::ptr_type = LIBCOPP_COPP_NAMESPACE_ID::util::intrusive_ptr<self_type>

Definition at line 41 of file task.h.

◆ self_t

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::self_t = self_type

Definition at line 51 of file task.h.

◆ self_type

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::self_type = task<macro_coroutine_type>

Definition at line 40 of file task.h.

◆ stack_allocator_t

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::stack_allocator_t = stack_allocator_type

Definition at line 54 of file task.h.

◆ stack_allocator_type

template<typename TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::stack_allocator_type = typename macro_coroutine_type::stack_allocator_type

Definition at line 44 of file task.h.

Constructor & Destructor Documentation

◆ task() [1/2]

template<typename TCO_MACRO = macro_coroutine>
task< TCO_MACRO >::task ( size_t  stack_sz)
inline

constuctor

Note
should not be called directly

Definition at line 72 of file task.h.

◆ ~task()

template<typename TCO_MACRO = macro_coroutine>
virtual task< TCO_MACRO >::~task ( )
inlinevirtual

◆ task() [2/2]

template<typename TCO_MACRO = macro_coroutine>
task< TCO_MACRO >::task ( const task< TCO_MACRO > &  )
privatedelete

Member Function Documentation

◆ _cas_status()

LIBCOPP_COTASK_API bool impl::task_impl::_cas_status ( EN_TASK_STATUS expected,
EN_TASK_STATUS  desired 
)
protectedinherited

◆ _get_action()

LIBCOPP_COTASK_API task_impl::action_ptr_type impl::task_impl::_get_action ( )
protectedinherited

Definition at line 67 of file task_impl.cpp.

References impl::task_impl::action_.

Referenced by impl::task_impl::_notify_finished().

◆ _notify_finished()

template<typename TCO_MACRO = macro_coroutine>
int task< TCO_MACRO >::_notify_finished ( void *  priv_data)
inlineprivate

Definition at line 739 of file task.h.

References impl::task_impl::_notify_finished().

◆ _set_action()

LIBCOPP_COTASK_API void impl::task_impl::_set_action ( action_ptr_type  action)
protectedinherited

Definition at line 65 of file task_impl.cpp.

References print_color::action, and impl::task_impl::action_.

◆ active_next_tasks()

template<typename TCO_MACRO = macro_coroutine>
void task< TCO_MACRO >::active_next_tasks ( )
inlineprivate

Definition at line 683 of file task.h.

References EN_TS_INVALID, and EN_TS_RUNNING.

◆ add_buffer_offset()

template<typename TCO_MACRO = macro_coroutine>
static void* task< TCO_MACRO >::add_buffer_offset ( void *  in,
size_t  off 
)
inlinestatic

Definition at line 644 of file task.h.

◆ await_task() [1/2]

template<typename TCO_MACRO = macro_coroutine>
int task< TCO_MACRO >::await_task ( ptr_type  wait_task)
inline

await_task 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_type a = ..., b = ...; a.await_task(b); b.await_task(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 326 of file task.h.

References COPP_EC_ARGS_ERROR, COPP_EC_TASK_ADD_NEXT_FAILED, COPP_EC_TASK_CAN_NOT_WAIT_SELF, COPP_EC_TASK_IS_EXITING, COPP_EC_TASK_NOT_IN_ACTION, this_coroutine::get(), impl::task_impl::is_exiting(), impl::task_impl::this_task(), and impl::task_impl::yield().

◆ await_task() [2/2]

template<typename TCO_MACRO = macro_coroutine>
template<typename TTask >
int task< TCO_MACRO >::await_task ( TTask *  wait_task)
inline

Definition at line 366 of file task.h.

◆ cancel() [1/2]

UTIL_FORCEINLINE int impl::task_impl::cancel ( )
inlineinherited

Definition at line 110 of file task_impl.h.

References impl::task_impl::cancel().

Referenced by impl::task_impl::cancel().

◆ cancel() [2/2]

template<typename TCO_MACRO = macro_coroutine>
int task< TCO_MACRO >::cancel ( void *  priv_data)
inlineoverridevirtual

◆ create() [1/6]

template<typename TCO_MACRO = macro_coroutine>
template<typename Ty >
static ptr_type task< TCO_MACRO >::create ( 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 151 of file task.h.

◆ create() [2/6]

template<typename TCO_MACRO = macro_coroutine>
template<typename Ty >
static ptr_type task< TCO_MACRO >::create ( Ty &&  functor,
typename coroutine_type::allocator_type &  alloc,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inlinestatic

Definition at line 157 of file task.h.

◆ create() [3/6]

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

Definition at line 181 of file task.h.

◆ create() [4/6]

template<typename TCO_MACRO = macro_coroutine>
template<typename Ty >
static ptr_type task< TCO_MACRO >::create ( Ty(*)(void *)  func,
typename coroutine_type::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 173 of file task.h.

◆ create() [5/6]

template<typename TCO_MACRO = macro_coroutine>
template<typename Ty , typename TInst >
static ptr_type task< TCO_MACRO >::create ( TyTInst::*  func,
TInst *  instance,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inlinestatic

Definition at line 202 of file task.h.

◆ create() [6/6]

template<typename TCO_MACRO = macro_coroutine>
template<typename Ty , typename TInst >
static LIBCOPP_COTASK_API_HEAD_ONLY ptr_type task< TCO_MACRO >::create ( TyTInst::*  func,
TInst *  instance,
typename coroutine_type::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 193 of file task.h.

◆ create_with()

template<typename TCO_MACRO = macro_coroutine>
template<typename Ty , typename... TParams>
static LIBCOPP_COTASK_API_HEAD_ONLY ptr_type task< TCO_MACRO >::create_with ( typename coroutine_type::allocator_type &  alloc,
size_t  stack_size,
size_t  private_buffer_size,
TParams &&...  args 
)
inlinestatic

create task with functor type and parameters

Parameters
stack_sizestack size
argsall parameters passed to construtor of type Ty
Returns
task smart pointer

Definition at line 215 of file task.h.

◆ create_with_delegate()

template<typename TCO_MACRO = macro_coroutine>
template<typename TAct , typename Ty >
static LIBCOPP_COTASK_API_HEAD_ONLY ptr_type task< TCO_MACRO >::create_with_delegate ( Ty &&  callable,
typename coroutine_type::allocator_type &  alloc,
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 91 of file task.h.

References print_color::action, COPP_MACRO_STD_FORWARD, impl::task_impl::ext_coroutine_flag_t::EN_ECFT_COTASK, and get_placement_destroy().

◆ get_coroutine_context() [1/2]

template<typename TCO_MACRO = macro_coroutine>
const coroutine_type::ptr_type& task< TCO_MACRO >::get_coroutine_context ( ) const
inline

Definition at line 438 of file task.h.

◆ get_coroutine_context() [2/2]

template<typename TCO_MACRO = macro_coroutine>
coroutine_type::ptr_type& task< TCO_MACRO >::get_coroutine_context ( )
inline

Definition at line 437 of file task.h.

◆ get_id()

UTIL_FORCEINLINE id_type impl::task_impl::get_id ( ) const
inlineinherited

Definition at line 74 of file task_impl.h.

Referenced by task_manager< task< TCO_MACRO > >::add_task(), and main().

◆ get_private_buffer()

template<typename TCO_MACRO = macro_coroutine>
void* task< TCO_MACRO >::get_private_buffer ( )
inline

Definition at line 652 of file task.h.

◆ get_private_buffer_size()

template<typename TCO_MACRO = macro_coroutine>
size_t task< TCO_MACRO >::get_private_buffer_size ( )
inline

Definition at line 660 of file task.h.

◆ get_raw_action()

UTIL_FORCEINLINE action_ptr_type 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 132 of file task_impl.h.

◆ get_ret_code()

template<typename TCO_MACRO = macro_coroutine>
int task< TCO_MACRO >::get_ret_code ( ) const
inlineoverridevirtual

Implements impl::task_impl.

Definition at line 443 of file task.h.

◆ get_status()

UTIL_FORCEINLINE EN_TASK_STATUS impl::task_impl::get_status ( ) const
inlineinherited

◆ is_canceled()

LIBCOPP_COTASK_API bool impl::task_impl::is_canceled ( ) const
virtualinherited

Definition at line 39 of file task_impl.cpp.

References EN_TS_CANCELED, and impl::task_impl::get_status().

◆ is_completed()

template<typename TCO_MACRO = macro_coroutine>
bool task< TCO_MACRO >::is_completed ( ) const
inlineoverridevirtual

Reimplemented from impl::task_impl.

Definition at line 630 of file task.h.

◆ is_exiting()

LIBCOPP_COTASK_API bool 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 47 of file task_impl.cpp.

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

Referenced by task_manager< task< TCO_MACRO > >::add_task(), task< TCO_MACRO >::await_task(), impl::task_impl::is_completed(), and task< TCO_MACRO >::next().

◆ is_faulted()

LIBCOPP_COTASK_API bool impl::task_impl::is_faulted ( ) const
virtualinherited

Definition at line 43 of file task_impl.cpp.

References EN_TS_KILLED, and impl::task_impl::get_status().

◆ is_timeout()

LIBCOPP_COTASK_API bool impl::task_impl::is_timeout ( ) const
virtualinherited

Definition at line 45 of file task_impl.cpp.

References EN_TS_TIMEOUT, and impl::task_impl::get_status().

◆ kill() [1/4]

UTIL_FORCEINLINE int impl::task_impl::kill ( )
inlineinherited

Definition at line 112 of file task_impl.h.

References impl::task_impl::kill().

Referenced by impl::task_impl::kill(), and task< TCO_MACRO >::~task().

◆ kill() [2/4]

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

Definition at line 111 of file task_impl.h.

References impl::task_impl::kill().

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

◆ kill() [3/4]

template<typename TCO_MACRO = macro_coroutine>
int task< TCO_MACRO >::kill ( enum EN_TASK_STATUS  status,
void *  priv_data 
)
inlineoverridevirtual

◆ kill() [4/4]

UTIL_FORCEINLINE int impl::task_impl::kill ( void *  priv_data)
inlineinherited

Definition at line 105 of file task_impl.h.

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

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

◆ next() [1/7]

template<typename TCO_MACRO = macro_coroutine>
ptr_type task< TCO_MACRO >::next ( ptr_type  next_task,
void *  priv_data = 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_type 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 231 of file task.h.

References EN_TS_CREATED, EN_TS_WAITING, impl::task_impl::is_completed(), and impl::task_impl::is_exiting().

◆ next() [2/7]

template<typename TCO_MACRO = macro_coroutine>
template<typename Ty >
ptr_type task< TCO_MACRO >::next ( Ty &&  functor,
typename coroutine_type::allocator_type &  alloc,
void *  priv_data = nullptr,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inline

Definition at line 272 of file task.h.

◆ next() [3/7]

template<typename TCO_MACRO = macro_coroutine>
template<typename Ty >
ptr_type task< TCO_MACRO >::next ( Ty &&  functor,
void *  priv_data = 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 267 of file task.h.

◆ next() [4/7]

template<typename TCO_MACRO = macro_coroutine>
template<typename Ty >
ptr_type task< TCO_MACRO >::next ( Ty(*)(void *)  func,
typename coroutine_type::allocator_type &  alloc,
void *  priv_data = nullptr,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inline

Definition at line 292 of file task.h.

◆ next() [5/7]

template<typename TCO_MACRO = macro_coroutine>
template<typename Ty >
ptr_type task< TCO_MACRO >::next ( Ty(*)(void *)  func,
void *  priv_data = 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 286 of file task.h.

◆ next() [6/7]

template<typename TCO_MACRO = macro_coroutine>
template<typename Ty , typename TInst >
ptr_type task< TCO_MACRO >::next ( TyTInst::*  func,
TInst *  instance,
typename coroutine_type::allocator_type &  alloc,
void *  priv_data = nullptr,
size_t  stack_size = 0,
size_t  private_buffer_size = 0 
)
inline

Definition at line 313 of file task.h.

◆ next() [7/7]

template<typename TCO_MACRO = macro_coroutine>
template<typename Ty , typename TInst >
ptr_type task< TCO_MACRO >::next ( TyTInst::*  func,
TInst *  instance,
void *  priv_data = 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 307 of file task.h.

◆ on_finished()

LIBCOPP_COTASK_API int impl::task_impl::on_finished ( )
virtualinherited

Definition at line 49 of file task_impl.cpp.

Referenced by impl::task_impl::_notify_finished().

◆ resume() [1/2]

UTIL_FORCEINLINE int impl::task_impl::resume ( )
inlineinherited

Definition at line 108 of file task_impl.h.

References impl::task_impl::resume().

Referenced by impl::task_impl::resume().

◆ resume() [2/2]

template<typename TCO_MACRO = macro_coroutine>
int task< TCO_MACRO >::resume ( void *  priv_data,
EN_TASK_STATUS  expected_status = EN_TS_WAITING 
)
inlineoverridevirtual

Implements impl::task_impl.

Definition at line 543 of file task.h.

References impl::task_impl::start().

Referenced by main().

◆ start() [1/2]

UTIL_FORCEINLINE int impl::task_impl::start ( )
inlineinherited

Definition at line 107 of file task_impl.h.

References impl::task_impl::start().

Referenced by task< TCO_MACRO >::resume(), and impl::task_impl::start().

◆ start() [2/2]

template<typename TCO_MACRO = macro_coroutine>
int task< TCO_MACRO >::start ( void *  priv_data,
EN_TASK_STATUS  expected_status = EN_TS_CREATED 
)
inlineoverridevirtual

◆ sub_buffer_offset()

template<typename TCO_MACRO = macro_coroutine>
static void* task< TCO_MACRO >::sub_buffer_offset ( void *  in,
size_t  off 
)
inlinestatic

Definition at line 648 of file task.h.

◆ then() [1/3]

template<typename TCO_MACRO = macro_coroutine>
ptr_type task< TCO_MACRO >::then ( ptr_type  next_task,
void *  priv_data = 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_type 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 378 of file task.h.

◆ then() [2/3]

template<typename TCO_MACRO = macro_coroutine>
template<typename Ty >
ptr_type task< TCO_MACRO >::then ( Ty &&  functor,
void *  priv_data = nullptr 
)
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 388 of file task.h.

◆ then() [3/3]

template<typename TCO_MACRO = macro_coroutine>
template<typename Ty >
ptr_type task< TCO_MACRO >::then ( Ty(*)(void *)  func,
void *  priv_data = nullptr 
)
inline

Definition at line 399 of file task.h.

◆ this_task()

template<typename TCO_MACRO = macro_coroutine>
static self_type* task< TCO_MACRO >::this_task ( )
inlinestatic

get current running task and convert to task object

Returns
task smart pointer

Definition at line 411 of file task.h.

References impl::task_impl::this_task().

◆ use_count()

template<typename TCO_MACRO = macro_coroutine>
size_t task< TCO_MACRO >::use_count ( ) const
inline

Definition at line 668 of file task.h.

◆ yield() [1/2]

UTIL_FORCEINLINE int impl::task_impl::yield ( )
inlineinherited

Definition at line 109 of file task_impl.h.

References impl::task_impl::yield().

Referenced by task< TCO_MACRO >::await_task(), and impl::task_impl::yield().

◆ yield() [2/2]

template<typename TCO_MACRO = macro_coroutine>
int task< TCO_MACRO >::yield ( void **  priv_data)
inlineoverridevirtual

Implements impl::task_impl.

Definition at line 548 of file task.h.

References COPP_EC_NOT_INITED.

Friends And Related Function Documentation

◆ intrusive_ptr_add_ref

template<typename TCO_MACRO = macro_coroutine>
void intrusive_ptr_add_ref ( self_type p)
friend

Definition at line 772 of file task.h.

◆ intrusive_ptr_release

template<typename TCO_MACRO = macro_coroutine>
void intrusive_ptr_release ( self_type p)
friend

Definition at line 780 of file task.h.

Field Documentation

◆ action_

action_ptr_type impl::task_impl::action_
privateinherited

Definition at line 147 of file task_impl.h.

Referenced by impl::task_impl::_get_action(), and impl::task_impl::_set_action().

◆ action_destroy_fn_

template<typename TCO_MACRO = macro_coroutine>
void(* task< TCO_MACRO >::action_destroy_fn_) (void *)
private

Definition at line 929 of file task.h.

◆ coroutine_obj_

template<typename TCO_MACRO = macro_coroutine>
coroutine_type::ptr_type task< TCO_MACRO >::coroutine_obj_
private

Definition at line 925 of file task.h.

◆ finish_priv_data_

void* impl::task_impl::finish_priv_data_
protectedinherited

Definition at line 151 of file task_impl.h.

Referenced by impl::task_impl::_notify_finished().

◆ id_

id_type impl::task_impl::id_
privateinherited

Definition at line 148 of file task_impl.h.

Referenced by impl::task_impl::task_impl(), and impl::task_impl::~task_impl().

◆ inner_action_lock_

template<typename TCO_MACRO = macro_coroutine>
LIBCOPP_COPP_NAMESPACE_ID::util::lock::spin_lock task< TCO_MACRO >::inner_action_lock_
private

ref_count

Definition at line 933 of file task.h.

◆ next_list_

template<typename TCO_MACRO = macro_coroutine>
task_group task< TCO_MACRO >::next_list_
private

Definition at line 926 of file task.h.

◆ ref_count_

template<typename TCO_MACRO = macro_coroutine>
LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type<size_t> task< TCO_MACRO >::ref_count_
private

Definition at line 932 of file task.h.

◆ stack_size_

template<typename TCO_MACRO = macro_coroutine>
size_t task< TCO_MACRO >::stack_size_
private

Definition at line 924 of file task.h.

◆ status_

LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type<uint32_t> impl::task_impl::status_
privateinherited

Definition at line 155 of file task_impl.h.

Referenced by impl::task_impl::_cas_status().


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