libcopp  1.3.0
task_impl.h
Go to the documentation of this file.
1 /*
2  * task_impl.h
3  *
4  * Created on: 2014年4月2日
5  * Author: owent
6  *
7  * Released under the MIT license
8  */
9 
10 #ifndef COTASK_IMPL_TASK_IMPL_H
11 #define COTASK_IMPL_TASK_IMPL_H
12 
13 #pragma once
14 
15 #include <list>
16 #include <stdint.h>
17 
22 
25 
26 #include <libcotask/task_actions.h>
27 
28 namespace cotask {
38  };
39 
40  namespace impl {
41 
43  protected:
45 
47  enum type {
48  EN_ECFT_UNKNOWN = 0,
49  EN_ECFT_COTASK = 0x0100,
50  EN_ECFT_MASK = 0xFF00,
51  };
52  };
53 
54  private:
55  task_impl(const task_impl &) UTIL_CONFIG_DELETED_FUNCTION;
56  task_impl &operator=(const task_impl &) UTIL_CONFIG_DELETED_FUNCTION;
57 
58 #if defined(UTIL_CONFIG_COMPILER_CXX_RVALUE_REFERENCES) && UTIL_CONFIG_COMPILER_CXX_RVALUE_REFERENCES
59  task_impl(const task_impl &&) UTIL_CONFIG_DELETED_FUNCTION;
60  task_impl &operator=(const task_impl &&) UTIL_CONFIG_DELETED_FUNCTION;
61 #endif
62 
63  public:
65  LIBCOPP_COTASK_API virtual ~task_impl() = 0;
66 
72  return static_cast<EN_TASK_STATUS>(status_.load(libcopp::util::lock::memory_order_acquire));
73  }
74 
75  LIBCOPP_COTASK_API virtual bool is_canceled() const UTIL_CONFIG_NOEXCEPT;
76  LIBCOPP_COTASK_API virtual bool is_completed() const UTIL_CONFIG_NOEXCEPT;
77  LIBCOPP_COTASK_API virtual bool is_faulted() const UTIL_CONFIG_NOEXCEPT;
78  LIBCOPP_COTASK_API virtual bool is_timeout() const UTIL_CONFIG_NOEXCEPT;
86  LIBCOPP_COTASK_API bool is_exiting() const UTIL_CONFIG_NOEXCEPT;
87 
88  public:
89  LIBCOPP_COTASK_API virtual int get_ret_code() const = 0;
90 
91  virtual int start(void *priv_data, EN_TASK_STATUS expected_status = EN_TS_CREATED) = 0;
92  virtual int resume(void *priv_data, EN_TASK_STATUS expected_status = EN_TS_WAITING) = 0;
93  virtual int yield(void **priv_data) = 0;
94  virtual int cancel(void *priv_data) = 0;
95  virtual int kill(enum EN_TASK_STATUS status, void *priv_data) = 0;
96  UTIL_FORCEINLINE int kill(void *priv_data) { return kill(EN_TS_KILLED, priv_data); }
97 
98  UTIL_FORCEINLINE int start() { return start(UTIL_CONFIG_NULLPTR); };
99  UTIL_FORCEINLINE int resume() { return resume(UTIL_CONFIG_NULLPTR); };
100  UTIL_FORCEINLINE int yield() { return yield(UTIL_CONFIG_NULLPTR); };
101  UTIL_FORCEINLINE int cancel() { return cancel(UTIL_CONFIG_NULLPTR); };
102  UTIL_FORCEINLINE int kill(enum EN_TASK_STATUS status) { return kill(status, UTIL_CONFIG_NULLPTR); };
103  UTIL_FORCEINLINE int kill() { return kill(UTIL_CONFIG_NULLPTR); };
104 
105  LIBCOPP_COTASK_API virtual int on_finished();
106 
111  static LIBCOPP_COTASK_API task_impl *this_task();
112 
118  UTIL_FORCEINLINE action_ptr_t get_raw_action() const UTIL_CONFIG_NOEXCEPT { return action_; }
119 
120  protected:
121  LIBCOPP_COTASK_API void _set_action(action_ptr_t action);
122  LIBCOPP_COTASK_API action_ptr_t _get_action();
123 
124  LIBCOPP_COTASK_API bool _cas_status(EN_TASK_STATUS &expected, EN_TASK_STATUS desired);
125 
126  LIBCOPP_COTASK_API int _notify_finished(void *priv_data);
127 
128  private:
129  action_ptr_t action_;
130 
131  protected:
133 
134  private:
135 #if !defined(LIBCOPP_DISABLE_ATOMIC_LOCK) || !(LIBCOPP_DISABLE_ATOMIC_LOCK)
137 #else
139 #endif
140  };
141  } // namespace impl
142 } // namespace cotask
143 
144 
145 #endif /* TASK_IMPL_H_ */
UTIL_FORCEINLINE action_ptr_t get_raw_action() const UTIL_CONFIG_NOEXCEPT
get raw action pointer
Definition: task_impl.h:118
::libcopp::util::lock::atomic_int_type< uint32_t > status_
Definition: task_impl.h:136
UTIL_FORCEINLINE int cancel()
Definition: task_impl.h:101
UTIL_FORCEINLINE EN_TASK_STATUS get_status() const UTIL_CONFIG_NOEXCEPT
Definition: task_impl.h:71
#define UTIL_SYMBOL_VISIBLE
action_ptr_t action_
Definition: task_impl.h:129
LIBCOPP_COPP_API int yield(void **priv_data=UTIL_CONFIG_NULLPTR)
yield current coroutine
自旋锁 Licensed under the MIT licenses.
EN_TASK_STATUS
Definition: task_impl.h:29
锁管理器 Licensed under the MIT licenses.
#define UTIL_FORCEINLINE
UTIL_FORCEINLINE int kill(enum EN_TASK_STATUS status)
Definition: task_impl.h:102
#define LIBCOPP_COTASK_API
UTIL_FORCEINLINE int resume()
Definition: task_impl.h:99
task_action_impl * action_ptr_t
Definition: task_impl.h:44
UTIL_FORCEINLINE int yield()
Definition: task_impl.h:100
整数类型的原子操作跨平台适配 Licensed under the MIT licenses.
导入智能指针库 Licensed under the MIT licenses.
UTIL_FORCEINLINE int start()
Definition: task_impl.h:98
UTIL_FORCEINLINE int kill(void *priv_data)
Definition: task_impl.h:96
UTIL_FORCEINLINE int kill()
Definition: task_impl.h:103