libcopp  1.3.0
task_impl.cpp
Go to the documentation of this file.
1 /*
2  * task_impl.cpp
3  *
4  * Created on: 2014年4月2日
5  * Author: owent
6  *
7  * Released under the MIT license
8  */
9 
10 #include <algorithm>
11 #include <cstdlib>
12 
13 #include <assert.h>
14 
18 
19 
20 namespace cotask {
21  namespace impl {
23  : action_(UTIL_CONFIG_NULLPTR), finish_priv_data_(UTIL_CONFIG_NULLPTR), status_(EN_TS_CREATED) {}
24 
25  LIBCOPP_COTASK_API task_impl::~task_impl() { assert(status_ <= EN_TS_CREATED || status_ >= EN_TS_DONE); }
26 
27  LIBCOPP_COTASK_API bool task_impl::is_canceled() const UTIL_CONFIG_NOEXCEPT { return EN_TS_CANCELED == get_status(); }
28 
29  LIBCOPP_COTASK_API bool task_impl::is_completed() const UTIL_CONFIG_NOEXCEPT { return is_exiting(); }
30 
31  LIBCOPP_COTASK_API bool task_impl::is_faulted() const UTIL_CONFIG_NOEXCEPT { return EN_TS_KILLED <= get_status(); }
32 
33  LIBCOPP_COTASK_API bool task_impl::is_timeout() const UTIL_CONFIG_NOEXCEPT { return EN_TS_TIMEOUT == get_status(); }
34 
35  LIBCOPP_COTASK_API bool task_impl::is_exiting() const UTIL_CONFIG_NOEXCEPT { return EN_TS_DONE <= get_status(); }
36 
38 
41  if (UTIL_CONFIG_NULLPTR == this_co) {
42  return UTIL_CONFIG_NULLPTR;
43  }
44 
45  if (false == this_co->check_flags(ext_coroutine_flag_t::EN_ECFT_COTASK)) {
46  return UTIL_CONFIG_NULLPTR;
47  }
48 
49  return *((task_impl **)this_co->get_private_buffer());
50  }
51 
53 
55 
57  uint32_t expected_int = expected;
60  expected = static_cast<EN_TASK_STATUS>(expected_int);
61  return ret;
62  }
63 
65  finish_priv_data_ = priv_data;
66 
67  _get_action()->on_finished(*this);
68  int ret = on_finished();
69 
70  return ret;
71  }
72  } // namespace impl
73 } // namespace cotask
virtual LIBCOPP_COTASK_API bool is_canceled() const UTIL_CONFIG_NOEXCEPT
Definition: task_impl.cpp:27
::libcopp::util::lock::atomic_int_type< uint32_t > status_
Definition: task_impl.h:136
UTIL_FORCEINLINE EN_TASK_STATUS get_status() const UTIL_CONFIG_NOEXCEPT
Definition: task_impl.h:71
LIBCOPP_COTASK_API bool _cas_status(EN_TASK_STATUS &expected, EN_TASK_STATUS desired)
Definition: task_impl.cpp:56
action_ptr_t action_
Definition: task_impl.h:129
UTIL_FORCEINLINE void * get_private_buffer() const UTIL_CONFIG_NOEXCEPT
get private buffer(raw pointer)
EN_TASK_STATUS
Definition: task_impl.h:29
LIBCOPP_COTASK_API void _set_action(action_ptr_t action)
Definition: task_impl.cpp:52
#define LIBCOPP_COTASK_API
LIBCOPP_COTASK_API int _notify_finished(void *priv_data)
Definition: task_impl.cpp:64
LIBCOPP_COTASK_API action_ptr_t _get_action()
Definition: task_impl.cpp:54
virtual LIBCOPP_COTASK_API ~task_impl()=0
Definition: task_impl.cpp:25
LIBCOPP_COTASK_API bool is_exiting() const UTIL_CONFIG_NOEXCEPT
check if a cotask is exiting
Definition: task_impl.cpp:35
LIBCOPP_COTASK_API task_impl()
Definition: task_impl.cpp:22
LIBCOPP_COPP_API coroutine_context * get_coroutine() UTIL_CONFIG_NOEXCEPT
get current coroutine
bool compare_exchange_weak(value_type &expected, value_type desired, EXPLICIT_UNUSED_ATTR::libcopp::util::lock::memory_order success, EXPLICIT_UNUSED_ATTR::libcopp::util::lock::memory_order failure) UTIL_CONFIG_NOEXCEPT
LIBCOPP_COPP_API bool check_flags(int flags) const
check flags
virtual LIBCOPP_COTASK_API int on_finished()
Definition: task_impl.cpp:37
virtual LIBCOPP_COTASK_API bool is_completed() const UTIL_CONFIG_NOEXCEPT
Definition: task_impl.cpp:29
virtual int on_finished(task_impl &)
base type of all coroutine context
virtual LIBCOPP_COTASK_API bool is_timeout() const UTIL_CONFIG_NOEXCEPT
Definition: task_impl.cpp:33
static LIBCOPP_COTASK_API task_impl * this_task()
Definition: task_impl.cpp:39
virtual LIBCOPP_COTASK_API bool is_faulted() const UTIL_CONFIG_NOEXCEPT
Definition: task_impl.cpp:31