MCPcopy Create free account
hub / github.com/AimRT/AimRT / ExecuteLoop

Method ExecuteLoop

src/interface/aimrt_module_cpp_interface/executor/timer.h:83–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81
82 private:
83 void ExecuteLoop() {
84 auto shared_this = this->shared_from_this();
85 executor_.ExecuteAt(next_call_time_, [shared_this, planned_time = next_call_time_]() {
86 if (shared_this->IsCancelled()) {
87 return;
88 }
89
90 // Skip current execution if timer was reset or restarted
91 if (planned_time != shared_this->next_call_time_) {
92 return;
93 }
94
95 shared_this->ExecuteTask();
96
97 auto now = shared_this->executor_.Now();
98 shared_this->next_call_time_ = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
99 shared_this->next_call_time_ + shared_this->period_);
100
101 // If now is ahead of the next call time, skip some times.
102 if (shared_this->next_call_time_ < now) {
103 if (shared_this->period_ == std::chrono::nanoseconds::zero()) {
104 shared_this->next_call_time_ = now;
105 } else {
106 auto now_ahead = now - shared_this->next_call_time_;
107 auto skip_count = 1 + ((now_ahead - std::chrono::nanoseconds(1)) / shared_this->period_);
108 shared_this->next_call_time_ = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
109 shared_this->next_call_time_ + (skip_count * shared_this->period_));
110 }
111 }
112
113 shared_this->ExecuteLoop();
114 });
115 }
116
117 private:
118 TaskType task_;

Callers

nothing calls this directly

Calls 4

IsCancelledMethod · 0.80
ExecuteTaskMethod · 0.80
ExecuteAtMethod · 0.45
NowMethod · 0.45

Tested by

no test coverage detected