libcopp  1.1.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 
21 
24 
25 #include <libcotask/task_actions.h>
26 
27 namespace cotask {
37  };
38 
39  namespace impl {
40 
41  class task_impl {
42  protected:
44 
46  enum type {
48  EN_ECFT_COTASK = 0x0100,
49  EN_ECFT_MASK = 0xFF00,
50  };
51  };
52 
53  private:
54  task_impl(const task_impl &);
55 
56  public:
57  task_impl();
58  virtual ~task_impl() = 0;
59 
64  EN_TASK_STATUS get_status() const UTIL_CONFIG_NOEXCEPT {
66  }
67 
68  virtual bool is_canceled() const UTIL_CONFIG_NOEXCEPT;
69  virtual bool is_completed() const UTIL_CONFIG_NOEXCEPT;
70  virtual bool is_faulted() const UTIL_CONFIG_NOEXCEPT;
71  virtual bool is_timeout() const UTIL_CONFIG_NOEXCEPT;
79  bool is_exiting() const UTIL_CONFIG_NOEXCEPT;
80 
81  public:
82  virtual int get_ret_code() const = 0;
83 
84  virtual int start(void *priv_data, EN_TASK_STATUS expected_status = EN_TS_CREATED) = 0;
85  virtual int resume(void *priv_data, EN_TASK_STATUS expected_status = EN_TS_WAITING) = 0;
86  virtual int yield(void **priv_data) = 0;
87  virtual int cancel(void *priv_data) = 0;
88  virtual int kill(enum EN_TASK_STATUS status, void *priv_data) = 0;
89  inline int kill(void *priv_data) { return kill(EN_TS_KILLED, priv_data); }
90 
91  inline int start() { return start(UTIL_CONFIG_NULLPTR); };
92  inline int resume() { return resume(UTIL_CONFIG_NULLPTR); };
93  inline int yield() { return yield(UTIL_CONFIG_NULLPTR); };
94  inline int cancel() { return cancel(UTIL_CONFIG_NULLPTR); };
95  inline int kill(enum EN_TASK_STATUS status) { return kill(status, UTIL_CONFIG_NULLPTR); };
96  inline int kill() { return kill(UTIL_CONFIG_NULLPTR); };
97 
98  virtual int on_finished();
99 
104  static task_impl *this_task();
105 
111  inline action_ptr_t get_raw_action() const UTIL_CONFIG_NOEXCEPT { return action_; }
112 
113  protected:
114  void _set_action(action_ptr_t action);
115  action_ptr_t _get_action();
116 
117  bool _cas_status(EN_TASK_STATUS &expected, EN_TASK_STATUS desired);
118 
119  int _notify_finished(void *priv_data);
120 
121  private:
122  action_ptr_t action_;
123 
124  protected:
126 
127  private:
128 #if !defined(PROJECT_DISABLE_MT) || !(PROJECT_DISABLE_MT)
130 #else
132 #endif
133  };
134  } // namespace impl
135 } // namespace cotask
136 
137 
138 #endif /* TASK_IMPL_H_ */
int _notify_finished(void *priv_data)
Definition: task_impl.cpp:63
action_ptr_t get_raw_action() const UTIL_CONFIG_NOEXCEPT
get raw action pointer
Definition: task_impl.h:111
virtual bool is_canceled() const UTIL_CONFIG_NOEXCEPT
Definition: task_impl.cpp:26
virtual int on_finished()
Definition: task_impl.cpp:36
bool is_exiting() const UTIL_CONFIG_NOEXCEPT
check if a cotask is exiting
Definition: task_impl.cpp:34
action_ptr_t action_
Definition: task_impl.h:122
virtual int get_ret_code() const =0
bool _cas_status(EN_TASK_STATUS &expected, EN_TASK_STATUS desired)
Definition: task_impl.cpp:55
action_ptr_t _get_action()
Definition: task_impl.cpp:53
::util::lock::atomic_int_type< uint32_t > status_
Definition: task_impl.h:129
EN_TASK_STATUS get_status() const UTIL_CONFIG_NOEXCEPT
Definition: task_impl.h:64
自旋锁 Licensed under the MIT licenses.
virtual bool is_faulted() const UTIL_CONFIG_NOEXCEPT
Definition: task_impl.cpp:30
EN_TASK_STATUS
Definition: task_impl.h:28
锁管理器 Licensed under the MIT licenses.
void _set_action(action_ptr_t action)
Definition: task_impl.cpp:51
task_action_impl * action_ptr_t
Definition: task_impl.h:43
整数类型的原子操作跨平台适配 Licensed under the MIT licenses.
导入智能指针库 Licensed under the MIT licenses.
int kill(void *priv_data)
Definition: task_impl.h:89
virtual ~task_impl()=0
Definition: task_impl.cpp:24
value_type load(::util::lock::memory_order order=::util::lock::memory_order_seq_cst) const UTIL_CONFIG_NOEXCEPT
virtual bool is_completed() const UTIL_CONFIG_NOEXCEPT
Definition: task_impl.cpp:28
virtual bool is_timeout() const UTIL_CONFIG_NOEXCEPT
Definition: task_impl.cpp:32
static task_impl * this_task()
Definition: task_impl.cpp:38
int kill(enum EN_TASK_STATUS status)
Definition: task_impl.h:95