libcopp
2.2.0
|
#include <task.h>
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_type * | this_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) |
|
private |
|
private |
using task< TCO_MACRO >::coroutine_t = coroutine_type |
using task< TCO_MACRO >::coroutine_type = typename macro_coroutine_type::coroutine_type |
using task< TCO_MACRO >::id_allocator_t = id_allocator_type |
using task< TCO_MACRO >::id_allocator_type = typename impl::task_impl::id_allocator_type |
using task< TCO_MACRO >::id_type = typename impl::task_impl::id_type |
using task< TCO_MACRO >::macro_coroutine_t = macro_coroutine_type |
using task< TCO_MACRO >::macro_coroutine_type = TCO_MACRO |
using task< TCO_MACRO >::self_type = task<macro_coroutine_type> |
using task< TCO_MACRO >::stack_allocator_t = stack_allocator_type |
using task< TCO_MACRO >::stack_allocator_type = typename macro_coroutine_type::stack_allocator_type |
Definition at line 420 of file task.h.
References EN_TS_CREATED, EN_TS_TIMEOUT, impl::task_impl::get_status(), and impl::task_impl::kill().
|
privatedelete |
|
protectedinherited |
Definition at line 69 of file task_impl.cpp.
References util::lock::memory_order_acq_rel, util::lock::memory_order_acquire, and impl::task_impl::status_.
Referenced by task< TCO_MACRO >::cancel(), task< TCO_MACRO >::kill(), and task< TCO_MACRO >::start().
|
protectedinherited |
Definition at line 67 of file task_impl.cpp.
References impl::task_impl::action_.
Referenced by impl::task_impl::_notify_finished().
|
inlineprivate |
Definition at line 739 of file task.h.
References impl::task_impl::_notify_finished().
|
protectedinherited |
Definition at line 65 of file task_impl.cpp.
References print_color::action, and impl::task_impl::action_.
|
inlineprivate |
Definition at line 683 of file task.h.
References EN_TS_INVALID, and EN_TS_RUNNING.
|
inlinestatic |
|
inline |
await_task another cotask to finish
wait_task | which stack to wait for |
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().
|
inline |
|
inlineinherited |
Definition at line 110 of file task_impl.h.
References impl::task_impl::cancel().
Referenced by impl::task_impl::cancel().
|
inlineoverridevirtual |
Implements impl::task_impl.
Definition at line 566 of file task.h.
References impl::task_impl::_cas_status(), impl::task_impl::_notify_finished(), COPP_EC_IS_RUNNING, COPP_EC_SUCCESS, COPP_LIKELY_IF, EN_TS_CANCELED, EN_TS_RUNNING, and impl::task_impl::get_status().
|
inlinestatic |
|
inlinestatic |
create task with functor
action | |
stack_size | stack size |
private_buffer_size | buffer size to store private data |
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().
|
inline |
|
inline |
|
inlineinherited |
Definition at line 74 of file task_impl.h.
Referenced by task_manager< task< TCO_MACRO > >::add_task(), and main().
|
inline |
|
inline |
|
inlineinherited |
get raw action pointer
Definition at line 132 of file task_impl.h.
|
inlineoverridevirtual |
Implements impl::task_impl.
|
inlineinherited |
get task status
Definition at line 80 of file task_impl.h.
References util::lock::memory_order_acquire.
Referenced by task< TCO_MACRO >::cancel(), impl::task_impl::is_canceled(), impl::task_impl::is_exiting(), impl::task_impl::is_faulted(), impl::task_impl::is_timeout(), task< TCO_MACRO >::kill(), and task< TCO_MACRO >::~task().
|
virtualinherited |
Definition at line 39 of file task_impl.cpp.
References EN_TS_CANCELED, and impl::task_impl::get_status().
|
inlineoverridevirtual |
Reimplemented from impl::task_impl.
|
inherited |
check 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().
|
virtualinherited |
Definition at line 43 of file task_impl.cpp.
References EN_TS_KILLED, and impl::task_impl::get_status().
|
virtualinherited |
Definition at line 45 of file task_impl.cpp.
References EN_TS_TIMEOUT, and impl::task_impl::get_status().
|
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().
|
inlineinherited |
Definition at line 111 of file task_impl.h.
References impl::task_impl::kill().
Referenced by impl::task_impl::kill().
|
inlineoverridevirtual |
Implements impl::task_impl.
Definition at line 600 of file task.h.
References impl::task_impl::_cas_status(), impl::task_impl::_notify_finished(), COPP_EC_SUCCESS, COPP_LIKELY_IF, EN_TS_RUNNING, and impl::task_impl::get_status().
|
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().
|
inline |
add next task to run when task finished
next_task | next stack |
priv_data | priv_data passed to resume or start next stack |
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().
|
virtualinherited |
Definition at line 49 of file task_impl.cpp.
Referenced by impl::task_impl::_notify_finished().
|
inlineinherited |
Definition at line 108 of file task_impl.h.
References impl::task_impl::resume().
Referenced by impl::task_impl::resume().
|
inlineoverridevirtual |
Implements impl::task_impl.
Definition at line 543 of file task.h.
References impl::task_impl::start().
Referenced by main().
|
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().
|
inlineoverridevirtual |
Implements impl::task_impl.
Definition at line 462 of file task.h.
References impl::task_impl::_cas_status(), impl::task_impl::_notify_finished(), COPP_EC_ALREADY_FINISHED, COPP_EC_IS_RUNNING, COPP_EC_NOT_INITED, COPP_LIKELY_IF, COPP_UNLIKELY_IF, EN_TS_DONE, EN_TS_RUNNING, EN_TS_WAITING, and impl::task_impl::is_completed().
Referenced by main().
|
inlinestatic |
|
inline |
add task to run when task finished
next_task | then stack |
priv_data | priv_data passed to resume or start the stack |
|
inlinestatic |
get current running task and convert to task object
Definition at line 411 of file task.h.
References impl::task_impl::this_task().
|
inline |
|
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().
|
inlineoverridevirtual |
|
friend |
|
friend |
|
privateinherited |
Definition at line 147 of file task_impl.h.
Referenced by impl::task_impl::_get_action(), and impl::task_impl::_set_action().
|
private |
|
private |
|
protectedinherited |
Definition at line 151 of file task_impl.h.
Referenced by impl::task_impl::_notify_finished().
|
privateinherited |
Definition at line 148 of file task_impl.h.
Referenced by impl::task_impl::task_impl(), and impl::task_impl::~task_impl().
|
private |
|
private |
|
private |
|
private |
|
privateinherited |
Definition at line 155 of file task_impl.h.
Referenced by impl::task_impl::_cas_status().