libcopp 2.3.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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::memory::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
 
ptr_type next (ptr_type next_task, void *priv_data=nullptr)
 add next task to run when task finished
 
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
 
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
 
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
 
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
 
template<class TAWAITABLE , class TERROR_TRANSFORM , class = LIBCOPP_COPP_NAMESPACE_ID::nostd::enable_if_t<LIBCOPP_COPP_NAMESPACE_ID::stackful_inject_awaitable< LIBCOPP_COPP_NAMESPACE_ID::nostd::remove_cvref_t<TAWAITABLE>>::value>>
LIBCOPP_COPP_NAMESPACE_ID::container_value_type< TAWAITABLE > await_value (TAWAITABLE &&awaitable, TERROR_TRANSFORM &&error_transform) noexcept(std::is_nothrow_copy_constructible< LIBCOPP_COPP_NAMESPACE_ID::container_value_type< TAWAITABLE > >::value &&noexcept(error_transform(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ARGS_ERROR)))
 Waits for the specified awaitable object to finish and retrieves its result.
 
template<class TAWAITABLE , class = LIBCOPP_COPP_NAMESPACE_ID::nostd::enable_if_t<LIBCOPP_COPP_NAMESPACE_ID::stackful_inject_awaitable< LIBCOPP_COPP_NAMESPACE_ID::nostd::remove_cvref_t<TAWAITABLE>>::value>>
LIBCOPP_COPP_NAMESPACE_ID::container_value_type< TAWAITABLE > await_value (TAWAITABLE &&awaitable) noexcept(std::is_nothrow_copy_constructible< LIBCOPP_COPP_NAMESPACE_ID::container_value_type< TAWAITABLE > >::value &&noexcept(LIBCOPP_COPP_NAMESPACE_ID::stackful_channel_error_transform< LIBCOPP_COPP_NAMESPACE_ID::container_value_type< TAWAITABLE > >()(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ARGS_ERROR)))
 Waits for the specified awaitable object to finish and retrieves its result.
 
template<typename TTask >
int await_task (TTask *wait_task)
 await another task
 
ptr_type then (ptr_type next_task, void *priv_data=nullptr)
 add task to run when task finished
 
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
 
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
 
LIBCOPP_UTIL_FORCEINLINE id_type get_id () const LIBCOPP_MACRO_NOEXCEPT
 
LIBCOPP_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
 
LIBCOPP_UTIL_FORCEINLINE int start ()
 
LIBCOPP_UTIL_FORCEINLINE int resume ()
 
LIBCOPP_UTIL_FORCEINLINE int yield ()
 
LIBCOPP_UTIL_FORCEINLINE int cancel ()
 
LIBCOPP_UTIL_FORCEINLINE int kill (void *priv_data)
 
LIBCOPP_UTIL_FORCEINLINE int kill (enum EN_TASK_STATUS status)
 
LIBCOPP_UTIL_FORCEINLINE int kill ()
 
virtual LIBCOPP_COTASK_API int on_finished ()
 
LIBCOPP_UTIL_FORCEINLINE action_ptr_type get_raw_action () const LIBCOPP_MACRO_NOEXCEPT
 get raw action pointer
 

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
 
template<typename Ty >
static ptr_type create (Ty &&functor, size_t stack_size=0, size_t private_buffer_size=0)
 create task with functor
 
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
 
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
 
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
 
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< LIBCOPP_COPP_NAMESPACE_ID::util::lock::unsafe_int_type< size_t > > ref_count_
 
action_ptr_type action_
 
id_type id_
 
LIBCOPP_COPP_NAMESPACE_ID::util::lock::atomic_int_type< LIBCOPP_COPP_NAMESPACE_ID::util::lock::unsafe_int_type< uint32_t > > status_
 

Friends

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

Detailed Description

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

Definition at line 38 of file task.h.

Member Typedef Documentation

◆ action_ptr_t

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

Definition at line 62 of file task.h.

◆ action_ptr_type

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

Definition at line 60 of file task.h.

◆ coroutine_t

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

Definition at line 54 of file task.h.

◆ coroutine_type

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

Definition at line 44 of file task.h.

◆ id_allocator_t

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

Definition at line 56 of file task.h.

◆ id_allocator_type

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

Definition at line 48 of file task.h.

◆ id_t

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

Definition at line 57 of file task.h.

◆ id_type

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

Definition at line 47 of file task.h.

◆ macro_coroutine_t

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

Definition at line 51 of file task.h.

◆ macro_coroutine_type

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

Definition at line 40 of file task.h.

◆ ptr_t

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

Definition at line 53 of file task.h.

◆ ptr_type

template<class TCO_MACRO = macro_coroutine>
using task< TCO_MACRO >::ptr_type = LIBCOPP_COPP_NAMESPACE_ID::memory::intrusive_ptr<self_type>

Definition at line 42 of file task.h.

◆ self_t

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

Definition at line 52 of file task.h.

◆ self_type

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

Definition at line 41 of file task.h.

◆ stack_allocator_t

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

Definition at line 55 of file task.h.

◆ stack_allocator_type

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

Definition at line 45 of file task.h.

Constructor & Destructor Documentation

◆ task() [1/2]

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

constuctor

Note
should not be called directly

Definition at line 73 of file task.h.

◆ ~task()

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

◆ task() [2/2]

template<class 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

◆ _notify_finished()

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

Definition at line 800 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 impl::task_impl::action_.

Referenced by task< TCO_MACRO >::~task().

◆ active_next_tasks()

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

Definition at line 744 of file task.h.

References EN_TS_INVALID, and EN_TS_RUNNING.

◆ add_buffer_offset()

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

Definition at line 705 of file task.h.

◆ await_task() [1/2]

template<class 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 327 of file task.h.

References impl::task_impl::is_exiting(), impl::task_impl::this_task(), and impl::task_impl::yield().

◆ await_task() [2/2]

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

await another task

Returns
0 or error code

Definition at line 418 of file task.h.

◆ await_value() [1/2]

template<class TCO_MACRO = macro_coroutine>
template<class TAWAITABLE , class = LIBCOPP_COPP_NAMESPACE_ID::nostd::enable_if_t<LIBCOPP_COPP_NAMESPACE_ID::stackful_inject_awaitable< LIBCOPP_COPP_NAMESPACE_ID::nostd::remove_cvref_t<TAWAITABLE>>::value>>
LIBCOPP_COPP_NAMESPACE_ID::container_value_type< TAWAITABLE > task< TCO_MACRO >::await_value ( TAWAITABLE &&  awaitable)
inlinenoexcept

Waits for the specified awaitable object to finish and retrieves its result.

Parameters
awaitableThe awaitable object to be consumed.
Returns
The result of the awaitable object, of type TAWAITABLE::value_type. If any error happens it will call value_type's constructor and pass error code.

Definition at line 399 of file task.h.

◆ await_value() [2/2]

template<class TCO_MACRO = macro_coroutine>
template<class TAWAITABLE , class TERROR_TRANSFORM , class = LIBCOPP_COPP_NAMESPACE_ID::nostd::enable_if_t<LIBCOPP_COPP_NAMESPACE_ID::stackful_inject_awaitable< LIBCOPP_COPP_NAMESPACE_ID::nostd::remove_cvref_t<TAWAITABLE>>::value>>
LIBCOPP_COPP_NAMESPACE_ID::container_value_type< TAWAITABLE > task< TCO_MACRO >::await_value ( TAWAITABLE &&  awaitable,
TERROR_TRANSFORM &&  error_transform 
)
inlinenoexcept

Waits for the specified awaitable object to finish and retrieves its result.

Parameters
awaitableThe awaitable object to be consumed.
error_transformA callable object used to transform error code to return type if any occur.
Returns
The result of the awaitable object, of type TAWAITABLE::value_type.

Definition at line 378 of file task.h.

◆ cancel() [1/2]

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

Definition at line 112 of file task_impl.h.

References impl::task_impl::cancel().

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

◆ cancel() [2/2]

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

◆ create() [1/6]

template<class 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 152 of file task.h.

◆ create() [2/6]

template<class 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 158 of file task.h.

◆ create() [3/6]

template<class 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 182 of file task.h.

◆ create() [4/6]

template<class 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 174 of file task.h.

◆ create() [5/6]

template<class 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 203 of file task.h.

◆ create() [6/6]

template<class 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 194 of file task.h.

◆ create_with()

template<class 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 216 of file task.h.

◆ create_with_delegate()

template<class 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 92 of file task.h.

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

◆ get_coroutine_context() [1/2]

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

Definition at line 499 of file task.h.

◆ get_coroutine_context() [2/2]

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

Definition at line 498 of file task.h.

◆ get_id()

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

Definition at line 76 of file task_impl.h.

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

◆ get_private_buffer()

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

Definition at line 713 of file task.h.

◆ get_private_buffer_size()

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

Definition at line 721 of file task.h.

◆ get_raw_action()

LIBCOPP_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 134 of file task_impl.h.

◆ get_ret_code()

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

Implements impl::task_impl.

Definition at line 504 of file task.h.

◆ get_status()

LIBCOPP_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<class TCO_MACRO = macro_coroutine>
bool task< TCO_MACRO >::is_completed ( ) const
inlineoverridevirtual

Reimplemented from impl::task_impl.

Definition at line 691 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]

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

Definition at line 114 of file task_impl.h.

References impl::task_impl::kill().

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

◆ kill() [2/4]

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

Definition at line 113 of file task_impl.h.

References impl::task_impl::kill().

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

◆ kill() [3/4]

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

◆ kill() [4/4]

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

Definition at line 107 of file task_impl.h.

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

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

◆ next() [1/7]

template<class 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 232 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<class 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 273 of file task.h.

◆ next() [3/7]

template<class 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 268 of file task.h.

◆ next() [4/7]

template<class 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 293 of file task.h.

◆ next() [5/7]

template<class 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 287 of file task.h.

◆ next() [6/7]

template<class 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 314 of file task.h.

◆ next() [7/7]

template<class 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 308 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]

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

Definition at line 110 of file task_impl.h.

References impl::task_impl::resume().

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

◆ resume() [2/2]

template<class 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 604 of file task.h.

References impl::task_impl::start().

Referenced by main().

◆ start() [1/2]

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

Definition at line 109 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<class 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<class TCO_MACRO = macro_coroutine>
static void * task< TCO_MACRO >::sub_buffer_offset ( void *  in,
size_t  off 
)
inlinestatic

Definition at line 709 of file task.h.

◆ then() [1/3]

template<class 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 430 of file task.h.

◆ then() [2/3]

template<class 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 440 of file task.h.

◆ then() [3/3]

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

Definition at line 451 of file task.h.

◆ this_task()

template<class 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 463 of file task.h.

References impl::task_impl::this_task().

◆ use_count()

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

Definition at line 729 of file task.h.

◆ yield() [1/2]

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

Definition at line 111 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<class TCO_MACRO = macro_coroutine>
int task< TCO_MACRO >::yield ( void **  priv_data)
inlineoverridevirtual

Implements impl::task_impl.

Definition at line 609 of file task.h.

Friends And Related Symbol Documentation

◆ intrusive_ptr_add_ref

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

Definition at line 833 of file task.h.

◆ intrusive_ptr_release

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

Definition at line 841 of file task.h.

Field Documentation

◆ action_

action_ptr_type impl::task_impl::action_
privateinherited

Definition at line 149 of file task_impl.h.

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

◆ action_destroy_fn_

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

Definition at line 984 of file task.h.

◆ coroutine_obj_

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

Definition at line 980 of file task.h.

◆ finish_priv_data_

void* impl::task_impl::finish_priv_data_
protectedinherited

Definition at line 153 of file task_impl.h.

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

◆ id_

id_type impl::task_impl::id_
privateinherited

Definition at line 150 of file task_impl.h.

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

◆ next_list_

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

Definition at line 981 of file task.h.

◆ ref_count_

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

Definition at line 991 of file task.h.

◆ stack_size_

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

Definition at line 979 of file task.h.

◆ status_

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

Definition at line 161 of file task_impl.h.

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


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