libcopp  1.2.0
task_manager.h
Go to the documentation of this file.
1 /*
2  * task_manager.h
3  *
4  * Created on: 2014年6月16日
5  * Author: owent
6  *
7  * Released under the MIT license
8  */
9 
10 #ifndef COTASK_TASK_MANAGER_H
11 #define COTASK_TASK_MANAGER_H
12 
13 #pragma once
14 
15 #include <algorithm>
16 #include <assert.h>
17 #include <ctime>
18 #include <set>
19 #include <stdint.h>
20 #include <vector>
21 
22 #if (defined(__cplusplus) && __cplusplus >= 201103L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
23 #include <unordered_map>
24 #define COTASK_MACRO_MANAGER_USING_UNORDERED_MAP 1
25 #else
26 #include <map>
27 #endif
28 
29 #include <libcotask/task_macros.h>
30 
31 
32 namespace cotask {
33 
34  namespace detail {
35  struct tickspec_t {
36  time_t tv_sec; /* Seconds. */
37  int tv_nsec; /* Nanoseconds. */
38 
39  friend bool operator==(const tickspec_t &l, const tickspec_t &r) { return l.tv_sec == r.tv_sec && l.tv_nsec == r.tv_nsec; }
40 
41  friend bool operator!=(const tickspec_t &l, const tickspec_t &r) { return l.tv_sec != r.tv_sec || l.tv_nsec != r.tv_nsec; }
42 
43  friend bool operator<(const tickspec_t &l, const tickspec_t &r) {
44  return (l.tv_sec != r.tv_sec) ? l.tv_sec < r.tv_sec : l.tv_nsec < r.tv_nsec;
45  }
46 
47  friend bool operator<=(const tickspec_t &l, const tickspec_t &r) {
48  return (l.tv_sec != r.tv_sec) ? l.tv_sec <= r.tv_sec : l.tv_nsec <= r.tv_nsec;
49  }
50  };
51 
52  template <typename TTask>
53  struct task_timer_node {
55  typename TTask::id_t task_id;
56 
57  friend bool operator==(const task_timer_node &l, const task_timer_node &r) {
58  return l.expired_time == r.expired_time && l.task_id == r.task_id;
59  }
60 
61  friend bool operator!=(const task_timer_node &l, const task_timer_node &r) {
62  return l.expired_time != r.expired_time || l.task_id != r.task_id;
63  }
64 
65  friend bool operator<(const task_timer_node &l, const task_timer_node &r) {
66  if (l.expired_time != r.expired_time) {
67  return l.expired_time < r.expired_time;
68  }
69 
70  return l.task_id < r.task_id;
71  }
72 
73  friend bool operator<=(const task_timer_node &l, const task_timer_node &r) {
74  if (l.expired_time != r.expired_time) {
75  return l.expired_time <= r.expired_time;
76  }
77 
78  return l.task_id <= r.task_id;
79  }
80  };
81 
82  template <typename TTask>
84  typedef typename TTask::ptr_t task_ptr_t;
85 
86  task_ptr_t task_;
87  typename std::set<task_timer_node<TTask> >::iterator timer_node;
88  };
89 
90  } // namespace detail
91 
95  template <typename TTask,
96 #if defined(COTASK_MACRO_MANAGER_USING_UNORDERED_MAP)
97  typename TTaskContainer = std::unordered_map<typename TTask::id_t, detail::task_manager_node<TTask> >
98 #else
99  typename TTaskContainer = std::map<typename TTask::id_t, detail::task_manager_node<TTask> >
100 #endif
101  >
102  class task_manager {
103  public:
104  typedef TTask task_t;
105  typedef TTaskContainer container_t;
106  typedef typename task_t::id_t id_t;
107  typedef typename task_t::ptr_t task_ptr_t;
109  typedef std::shared_ptr<self_t> ptr_t;
110 
111  struct flag_t {
112  enum type {
113  EN_TM_NONE = 0x00,
114  EN_TM_IN_TICK = 0x01,
115  EN_TM_IN_RESET = 0x02,
116  };
117  };
118 
119  private:
120  struct flag_guard_t {
121  int * data_;
122  typename flag_t::type flag_;
123  inline flag_guard_t(int *flags, typename flag_t::type v) : data_(flags), flag_(v) {
124  if (NULL == data_ || (*data_ & flag_)) {
125  flag_ = flag_t::EN_TM_NONE;
126  data_ = NULL;
127  } else {
128  (*data_) |= flag_;
129  }
130  }
131  inline ~flag_guard_t() {
132  if (*this) {
133  (*data_) &= ~flag_;
134  }
135  }
136 
137  inline operator bool() { return NULL != data_ && flag_t::EN_TM_NONE != flag_; }
138  };
139 
140  public:
141  task_manager() : flags_(0) {
142  last_tick_time_.tv_sec = 0;
143  last_tick_time_.tv_nsec = 0;
144  }
145 
147  // safe remove all task
148  reset();
149  }
150 
151  void reset() {
152  flag_guard_t reset_flag(&flags_, flag_t::EN_TM_IN_RESET);
153  if (!reset_flag) {
154  return;
155  }
156 
157  std::vector<task_ptr_t> all_tasks;
158  // first, lock and reset all data
159  {
160 #if !defined(PROJECT_DISABLE_MT) || !(PROJECT_DISABLE_MT)
161  util::lock::lock_holder<util::lock::spin_lock> lock_guard(action_lock_);
162 #endif
163 
164  for (typename container_t::iterator iter = tasks_.begin(); iter != tasks_.end(); ++iter) {
165  all_tasks.push_back(iter->second.task_);
166  remove_timeout_timer(iter->second);
167  }
168 
169  tasks_.clear();
170  task_timeout_timer_.clear();
171  flags_ = 0;
172  last_tick_time_.tv_sec = 0;
173  last_tick_time_.tv_nsec = 0;
174  }
175 
176  // then, kill all tasks
177  for (typename std::vector<task_ptr_t>::iterator iter = all_tasks.begin(); iter != all_tasks.end(); ++iter) {
178  if (!(*iter)->is_exiting()) {
179  (*iter)->kill(EN_TS_KILLED);
180  }
181  }
182  }
183 
188  static ptr_t create() { return std::make_shared<self_t>(); }
189 
203  int add_task(const task_ptr_t &task, time_t timeout_sec, int timeout_nsec) {
204  if (!task) {
205  assert(task);
207  }
208 
209  if (flags_ & flag_t::EN_TM_IN_RESET) {
210  return copp::COPP_EC_IN_RESET;
211  }
212 
213  if (task->is_exiting()) {
215  }
216 
217  // try to cast type
218  typedef typename container_t::value_type pair_type;
220  task_node.task_ = task;
221  task_node.timer_node = task_timeout_timer_.end();
222 
223  if (!task_node.task_) {
224  assert(task_node.task_);
226  }
227 
228  // lock before we will operator tasks_
229 #if !defined(PROJECT_DISABLE_MT) || !(PROJECT_DISABLE_MT)
230  util::lock::lock_holder<util::lock::spin_lock> lock_guard(action_lock_);
231 #endif
232 
233  id_t task_id = task->get_id();
234  if (tasks_.end() != tasks_.find(task_id)) {
236  }
237 
238 #if defined(LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER) && LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER
239  if (!task_t::task_manager_helper::setup_task_manager(*task, reinterpret_cast<void *>(this), &task_cleanup_callback)) {
241  }
242 #endif
243 
244  // try to insert to container
245  std::pair<typename container_t::iterator, bool> res = tasks_.insert(pair_type(task_id, task_node));
246  if (false == res.second) {
247 #if defined(LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER) && LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER
248  task_t::task_manager_helper::cleanup_task_manager(*task, reinterpret_cast<void *>(this));
249 #endif
251  }
252 
253  // add timeout controller
254  set_timeout_timer(res.first->second, timeout_sec, timeout_nsec);
255  return copp::COPP_EC_SUCCESS;
256  }
257 
266  int add_task(const task_ptr_t &task) { return add_task(task, 0, 0); }
267 
282  int set_timeout(id_t id, time_t timeout_sec, int timeout_nsec) {
283  if (flags_ & flag_t::EN_TM_IN_RESET) {
284  return copp::COPP_EC_IN_RESET;
285  }
286 
287  {
288 #if !defined(PROJECT_DISABLE_MT) || !(PROJECT_DISABLE_MT)
289  util::lock::lock_holder<util::lock::spin_lock> lock_guard(action_lock_);
290 #endif
291 
292  typedef typename container_t::iterator iter_type;
293  iter_type iter = tasks_.find(id);
294  if (tasks_.end() == iter) return copp::COPP_EC_NOT_FOUND;
295 
296  set_timeout_timer(iter->second, timeout_sec, timeout_nsec);
297  }
298 
299  return copp::COPP_EC_SUCCESS;
300  }
301 
308  inline int remove_task(id_t id, const task_ptr_t &confirm_ptr) { return remove_task(id, confirm_ptr.get()); }
309 
315  inline int remove_task(id_t id) { return remove_task(id, UTIL_CONFIG_NULLPTR); }
316 
323  int remove_task(id_t id, const task_t *confirm_ptr) {
324  if (flags_ & flag_t::EN_TM_IN_RESET) {
325  return copp::COPP_EC_IN_RESET;
326  }
327 
328  task_ptr_t task_inst;
329  {
330 #if !defined(PROJECT_DISABLE_MT) || !(PROJECT_DISABLE_MT)
331  util::lock::lock_holder<util::lock::spin_lock> lock_guard(action_lock_);
332 #endif
333 
334  typedef typename container_t::iterator iter_type;
335  iter_type iter = tasks_.find(id);
336  if (tasks_.end() == iter) {
338  }
339  if (UTIL_CONFIG_NULLPTR != confirm_ptr && iter->second.task_.get() != confirm_ptr) {
341  }
342 
343  // make sure running task be killed first
344  task_inst = COPP_MACRO_STD_MOVE(iter->second.task_);
345 
346  remove_timeout_timer(iter->second);
347  tasks_.erase(iter);
348  }
349 
350  if (task_inst) {
351 #if defined(LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER) && LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER
352  // already cleanup, there is no need to cleanup again
353  task_t::task_manager_helper::cleanup_task_manager(*task_inst, reinterpret_cast<void *>(this));
354 #endif
355 
356  EN_TASK_STATUS task_status = task_inst->get_status();
357  if (task_status > EN_TS_CREATED && task_status < EN_TS_DONE) {
358  return task_inst->kill(EN_TS_KILLED, NULL);
359  }
360  }
361 
362  return copp::COPP_EC_SUCCESS;
363  }
364 
370  task_ptr_t find_task(id_t id) {
371  if (flags_ & flag_t::EN_TM_IN_RESET) {
372  return task_ptr_t();
373  }
374 
375 #if !defined(PROJECT_DISABLE_MT) || !(PROJECT_DISABLE_MT)
376  util::lock::lock_holder<util::lock::spin_lock> lock_guard(action_lock_);
377 #endif
378 
379  typedef typename container_t::iterator iter_type;
380  iter_type iter = tasks_.find(id);
381  if (tasks_.end() == iter) return task_ptr_t();
382 
383  return iter->second.task_;
384  }
385 
386  // int add_scheduler();
387  // int scheduling_once();
388  // int scheduling_loop();
389 
390  int start(id_t id, void *priv_data = NULL) {
391  if (flags_ & flag_t::EN_TM_IN_RESET) {
392  return copp::COPP_EC_IN_RESET;
393  }
394 
395  task_ptr_t task_inst;
396  {
397 #if !defined(PROJECT_DISABLE_MT) || !(PROJECT_DISABLE_MT)
398  util::lock::lock_holder<util::lock::spin_lock> lock_guard(action_lock_);
399 #endif
400 
401  typedef typename container_t::iterator iter_type;
402  iter_type iter = tasks_.find(id);
403  if (tasks_.end() == iter) return copp::COPP_EC_NOT_FOUND;
404 
405  task_inst = iter->second.task_;
406  }
407 
408  // unlock and then run start
409  if (task_inst) {
410  int ret = task_inst->start(priv_data);
411 
412  // if task is finished, remove it
413  if (task_inst->get_status() >= EN_TS_DONE) {
414  remove_task(id);
415  }
416 
417  return ret;
418  } else {
420  }
421  }
422 
423  int resume(id_t id, void *priv_data = NULL) {
424  if (flags_ & flag_t::EN_TM_IN_RESET) {
425  return copp::COPP_EC_IN_RESET;
426  }
427 
428  task_ptr_t task_inst;
429  {
430 #if !defined(PROJECT_DISABLE_MT) || !(PROJECT_DISABLE_MT)
431  util::lock::lock_holder<util::lock::spin_lock> lock_guard(action_lock_);
432 #endif
433 
434  typedef typename container_t::iterator iter_type;
435  iter_type iter = tasks_.find(id);
436  if (tasks_.end() == iter) return copp::COPP_EC_NOT_FOUND;
437 
438  task_inst = iter->second.task_;
439  }
440 
441  // unlock and then run resume
442  if (task_inst) {
443  int ret = task_inst->resume(priv_data);
444 
445  // if task is finished, remove it
446  if (task_inst->get_status() >= EN_TS_DONE) {
447  remove_task(id);
448  }
449 
450  return ret;
451  } else {
453  }
454  }
455 
456  int cancel(id_t id, void *priv_data = NULL) {
457  if (flags_ & flag_t::EN_TM_IN_RESET) {
458  return copp::COPP_EC_IN_RESET;
459  }
460 
461  task_ptr_t task_inst;
462  {
463 #if !defined(PROJECT_DISABLE_MT) || !(PROJECT_DISABLE_MT)
464  util::lock::lock_holder<util::lock::spin_lock> lock_guard(action_lock_);
465 #endif
466 
467  typedef typename container_t::iterator iter_type;
468  iter_type iter = tasks_.find(id);
469  if (tasks_.end() == iter) {
471  }
472 
473  task_inst = COPP_MACRO_STD_MOVE(iter->second.task_);
474 
475  remove_timeout_timer(iter->second);
476  tasks_.erase(iter); // remove from container
477  }
478 
479  // unlock and then run cancel
480  if (task_inst) {
481 #if defined(LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER) && LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER
482  // already cleanup, there is no need to cleanup again
483  task_t::task_manager_helper::cleanup_task_manager(*task_inst, reinterpret_cast<void *>(this));
484 #endif
485  return task_inst->cancel(priv_data);
486  } else {
488  }
489  }
490 
491  int kill(id_t id, enum EN_TASK_STATUS status, void *priv_data = NULL) {
492  if (flags_ & flag_t::EN_TM_IN_RESET) {
493  return copp::COPP_EC_IN_RESET;
494  }
495 
496  task_ptr_t task_inst;
497  {
498 #if !defined(PROJECT_DISABLE_MT) || !(PROJECT_DISABLE_MT)
499  util::lock::lock_holder<util::lock::spin_lock> lock_guard(action_lock_);
500 #endif
501 
502  typedef typename container_t::iterator iter_type;
503  iter_type iter = tasks_.find(id);
504  if (tasks_.end() == iter) {
506  }
507 
508  task_inst = COPP_MACRO_STD_MOVE(iter->second.task_);
509 
510  remove_timeout_timer(iter->second);
511  tasks_.erase(iter); // remove from container
512  }
513 
514  // unlock and then run kill
515  if (task_inst) {
516 #if defined(LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER) && LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER
517  // already cleanup, there is no need to cleanup again
518  task_t::task_manager_helper::cleanup_task_manager(*task_inst, reinterpret_cast<void *>(this));
519 #endif
520  return task_inst->kill(status, priv_data);
521  } else {
523  }
524  }
525 
526  int kill(id_t id, void *priv_data = NULL) { return kill(id, EN_TS_KILLED, priv_data); }
527 
536  int tick(time_t sec, int nsec = 0) {
537  detail::tickspec_t now_tick_time;
538  // time can not be back
539  if (sec < last_tick_time_.tv_sec || (sec == last_tick_time_.tv_sec && nsec <= last_tick_time_.tv_nsec)) {
540  return 0;
541  }
542 
543  now_tick_time.tv_sec = sec;
544  now_tick_time.tv_nsec = nsec;
545 
546  // we will ignore tick when in a recursive call
547  flag_guard_t tick_flag(&flags_, flag_t::EN_TM_IN_TICK);
548  if (!tick_flag) {
549  return copp::COPP_EC_SUCCESS;
550  }
551 
552  if (flags_ & flag_t::EN_TM_IN_RESET) {
553  return copp::COPP_EC_IN_RESET;
554  }
555 
556  // first tick, init and reset task timeout
557  if (0 == last_tick_time_.tv_sec && 0 == last_tick_time_.tv_nsec) {
558  // hold lock
559 #if !defined(PROJECT_DISABLE_MT) || !(PROJECT_DISABLE_MT)
560  util::lock::lock_holder<util::lock::spin_lock> lock_guard(action_lock_);
561 #endif
562 
563  std::set<detail::task_timer_node<task_t> > real_checkpoints;
564  for (typename std::set<detail::task_timer_node<task_t> >::iterator iter = task_timeout_timer_.begin();
565  task_timeout_timer_.end() != iter; ++iter) {
566  detail::task_timer_node<task_t> new_checkpoint = (*iter);
567  new_checkpoint.expired_time.tv_sec += sec;
568  new_checkpoint.expired_time.tv_nsec += nsec;
569  real_checkpoints.insert(new_checkpoint);
570  }
571 
572  task_timeout_timer_.swap(task_timeout_timer_);
573  last_tick_time_ = now_tick_time;
574  return copp::COPP_EC_SUCCESS;
575  }
576 
577  // remove timeout tasks
578  while (false == task_timeout_timer_.empty()) {
579  task_ptr_t task_inst;
580 
581  {
582  // hold lock
583 #if !defined(PROJECT_DISABLE_MT) || !(PROJECT_DISABLE_MT)
584  util::lock::lock_holder<util::lock::spin_lock> lock_guard(action_lock_);
585 #endif
586 
587  const typename std::set<detail::task_timer_node<task_t> >::value_type &timer_node = *task_timeout_timer_.begin();
588  // all tasks those expired time less than now are timeout
589  if (now_tick_time <= timer_node.expired_time) {
590  break;
591  }
592 
593  // check expire time(may be changed)
594  typedef typename container_t::iterator iter_type;
595 
596  iter_type iter = tasks_.find(timer_node.task_id);
597 
598  if (tasks_.end() != iter) {
599  // task may be removed before
600  task_inst = COPP_MACRO_STD_MOVE(iter->second.task_);
601 
602  remove_timeout_timer(iter->second);
603  tasks_.erase(iter); // remove from container
604  }
605  }
606 
607  // task call can not be used when lock is on
608  if (task_inst && !task_inst->is_exiting()) {
609 #if defined(LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER) && LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER
610  // already cleanup, there is no need to cleanup again
611  task_t::task_manager_helper::cleanup_task_manager(*task_inst, reinterpret_cast<void *>(this));
612 #endif
613  task_inst->kill(EN_TS_TIMEOUT);
614  }
615  }
616 
617  last_tick_time_ = now_tick_time;
618  return copp::COPP_EC_SUCCESS;
619  }
620 
625  size_t get_tick_checkpoint_size() const UTIL_CONFIG_NOEXCEPT { return task_timeout_timer_.size(); }
626 
631  size_t get_task_size() const UTIL_CONFIG_NOEXCEPT { return tasks_.size(); }
632 
637  detail::tickspec_t get_last_tick_time() const UTIL_CONFIG_NOEXCEPT { return last_tick_time_; }
638 
643  inline const container_t &get_container() const UTIL_CONFIG_NOEXCEPT { return tasks_; }
644 
649  inline const std::set<detail::task_timer_node<task_t> > &get_checkpoints() const UTIL_CONFIG_NOEXCEPT {
650  return task_timeout_timer_;
651  }
652 
653  private:
654  void set_timeout_timer(detail::task_manager_node<task_t> &node, time_t timeout_sec, int timeout_nsec) {
655  remove_timeout_timer(node);
656 
657  if (timeout_sec <= 0 && timeout_nsec <= 0) {
658  return;
659  }
660 
661  if (!node.task_) {
662  return;
663  }
664 
666  timer_node.task_id = node.task_->get_id();
667  timer_node.expired_time.tv_sec = last_tick_time_.tv_sec + timeout_sec;
668  timer_node.expired_time.tv_nsec = last_tick_time_.tv_nsec + timeout_nsec;
669 
670  std::pair<typename std::set<detail::task_timer_node<task_t> >::iterator, bool> res = task_timeout_timer_.insert(timer_node);
671  if (res.second) {
672  node.timer_node = res.first;
673  }
674  }
675 
677  if (node.timer_node != task_timeout_timer_.end()) {
678  task_timeout_timer_.erase(node.timer_node);
679  node.timer_node = task_timeout_timer_.end();
680  }
681  }
682 
683 #if defined(LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER) && LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER
684  static void task_cleanup_callback(void *self_ptr, task_t &task_inst) {
685  if (UTIL_CONFIG_NULLPTR == self_ptr) {
686  return;
687  }
688 
689  reinterpret_cast<self_t *>(self_ptr)->remove_task(task_inst.get_id(), &task_inst);
690  }
691 #endif
692 
693  private:
694  container_t tasks_;
696  std::set<detail::task_timer_node<task_t> > task_timeout_timer_;
697 
698 #if !defined(PROJECT_DISABLE_MT) || !(PROJECT_DISABLE_MT)
700 #endif
701  int flags_;
702  };
703 } // namespace cotask
704 
705 
706 #endif /* TASK_MANAGER_H_ */
COPP_EC_ALREADY_EXIST.
Definition: errno.h:29
std::set< detail::task_timer_node< task_t > > task_timeout_timer_
Definition: task_manager.h:696
friend bool operator==(const task_timer_node &l, const task_timer_node &r)
Definition: task_manager.h:57
COPP_EC_TASK_IS_EXITING.
Definition: errno.h:36
int kill(id_t id, enum EN_TASK_STATUS status, void *priv_data=NULL)
Definition: task_manager.h:491
COPP_EC_NOT_FOUND.
Definition: errno.h:28
size_t get_tick_checkpoint_size() const UTIL_CONFIG_NOEXCEPT
get timeout checkpoint number in this manager
Definition: task_manager.h:625
int tick(time_t sec, int nsec=0)
active tick event and deal with clock
Definition: task_manager.h:536
void remove_timeout_timer(detail::task_manager_node< task_t > &node)
Definition: task_manager.h:676
task_ptr_t find_task(id_t id)
find task by id
Definition: task_manager.h:370
int cancel(id_t id, void *priv_data=NULL)
Definition: task_manager.h:456
COPP_EC_SUCCESS.
Definition: errno.h:12
COPP_EC_TASK_ALREADY_IN_ANOTHER_MANAGER.
Definition: errno.h:39
COPP_EC_EXTERNAL_INSERT_FAILED.
Definition: errno.h:15
int remove_task(id_t id, const task_t *confirm_ptr)
remove task in this manager
Definition: task_manager.h:323
friend bool operator<=(const task_timer_node &l, const task_timer_node &r)
Definition: task_manager.h:73
EN_TASK_STATUS
Definition: task_impl.h:28
const container_t & get_container() const UTIL_CONFIG_NOEXCEPT
task container, this api is just used for provide information to users
Definition: task_manager.h:643
std::set< task_timer_node< TTask > >::iterator timer_node
Definition: task_manager.h:87
std::shared_ptr< self_t > ptr_t
Definition: task_manager.h:109
detail::tickspec_t last_tick_time_
Definition: task_manager.h:695
void set_timeout_timer(detail::task_manager_node< task_t > &node, time_t timeout_sec, int timeout_nsec)
Definition: task_manager.h:654
friend bool operator==(const tickspec_t &l, const tickspec_t &r)
Definition: task_manager.h:39
#define COPP_MACRO_STD_MOVE(x)
Definition: features.h:171
int remove_task(id_t id, const task_ptr_t &confirm_ptr)
remove task in this manager
Definition: task_manager.h:308
int kill(id_t id, void *priv_data=NULL)
Definition: task_manager.h:526
TTaskContainer container_t
Definition: task_manager.h:105
int add_task(const task_ptr_t &task)
add task to manager please make the task has method of get_id() and will return a unique id ...
Definition: task_manager.h:266
flag_guard_t(int *flags, typename flag_t::type v)
Definition: task_manager.h:123
friend bool operator!=(const tickspec_t &l, const tickspec_t &r)
Definition: task_manager.h:41
const std::set< detail::task_timer_node< task_t > > & get_checkpoints() const UTIL_CONFIG_NOEXCEPT
get all task checkpoints, this api is just used for provide information to users
Definition: task_manager.h:649
int add_task(const task_ptr_t &task, time_t timeout_sec, int timeout_nsec)
add task to manager please make the task has method of get_id() and will return a unique id ...
Definition: task_manager.h:203
task_manager< task_t, container_t > self_t
Definition: task_manager.h:108
int start(id_t id, void *priv_data=NULL)
Definition: task_manager.h:390
util::lock::spin_lock action_lock_
Definition: task_manager.h:699
COPP_EC_CAST_FAILED.
Definition: errno.h:31
friend bool operator!=(const task_timer_node &l, const task_timer_node &r)
Definition: task_manager.h:61
friend bool operator<=(const tickspec_t &l, const tickspec_t &r)
Definition: task_manager.h:47
COPP_EC_IN_RESET.
Definition: errno.h:17
detail::tickspec_t get_last_tick_time() const UTIL_CONFIG_NOEXCEPT
get last tick time
Definition: task_manager.h:637
task_t::ptr_t task_ptr_t
Definition: task_manager.h:107
int resume(id_t id, void *priv_data=NULL)
Definition: task_manager.h:423
static ptr_t create()
create a new task manager
Definition: task_manager.h:188
size_t get_task_size() const UTIL_CONFIG_NOEXCEPT
get task number in this manager
Definition: task_manager.h:631
std::shared_ptr< cli::cmd_option_value > value_type
Definition: cmd_option.h:53
int set_timeout(id_t id, time_t timeout_sec, int timeout_nsec)
set or update task timeout
Definition: task_manager.h:282
friend bool operator<(const tickspec_t &l, const tickspec_t &r)
Definition: task_manager.h:43
int remove_task(id_t id)
remove task in this manager
Definition: task_manager.h:315
friend bool operator<(const task_timer_node &l, const task_timer_node &r)
Definition: task_manager.h:65
COPP_EC_ARGS_ERROR.
Definition: errno.h:30