Apollo 10.0
自动驾驶开放平台
apollo::cyber::Timer类 参考

Used to perform oneshot or periodic timing tasks 更多...

#include <timer.h>

apollo::cyber::Timer 的协作图:

Public 成员函数

 Timer ()
 
 Timer (TimerOption opt)
 Construct a new Timer object
 
 Timer (uint32_t period, std::function< void()> callback, bool oneshot)
 Construct a new Timer object
 
 ~Timer ()
 
void SetTimerOption (TimerOption opt)
 Set the Timer Option object
 
void Start ()
 Start the timer
 
void Stop ()
 Stop the timer
 

详细描述

Used to perform oneshot or periodic timing tasks

在文件 timer.h71 行定义.

构造及析构函数说明

◆ Timer() [1/3]

apollo::cyber::Timer::Timer ( )

在文件 timer.cc31 行定义.

31 {
32 timing_wheel_ = TimingWheel::Instance();
33 timer_id_ = GenerateTimerId();
34}

◆ Timer() [2/3]

apollo::cyber::Timer::Timer ( TimerOption  opt)
explicit

Construct a new Timer object

参数
optTimer option

在文件 timer.cc36 行定义.

36 : timer_opt_(opt) {
37 timing_wheel_ = TimingWheel::Instance();
38 timer_id_ = GenerateTimerId();
39}

◆ Timer() [3/3]

apollo::cyber::Timer::Timer ( uint32_t  period,
std::function< void()>  callback,
bool  oneshot 
)

Construct a new Timer object

参数
periodThe period of the timer, unit is ms
callbackThe tasks that the timer needs to perform
oneshotTrue: perform the callback only after the first timing cycle False: perform the callback every timed period

在文件 timer.cc41 行定义.

41 {
42 timing_wheel_ = TimingWheel::Instance();
43 timer_id_ = GenerateTimerId();
44 timer_opt_.period = period;
45 timer_opt_.callback = callback;
46 timer_opt_.oneshot = oneshot;
47}
uint32_t period
The period of the timer, unit is ms max: 512 * 64 min: 1
Definition timer.h:54
bool oneshot
True: perform the callback only after the first timing cycle False: perform the callback every timed ...
Definition timer.h:63
std::function< void()> callback
The task that the timer needs to perform
Definition timer.h:57

◆ ~Timer()

apollo::cyber::Timer::~Timer ( )

在文件 timer.cc154 行定义.

154 {
155 if (task_) {
156 Stop();
157 }
158}
void Stop()
Stop the timer
Definition timer.cc:142

成员函数说明

◆ SetTimerOption()

void apollo::cyber::Timer::SetTimerOption ( TimerOption  opt)

Set the Timer Option object

参数
optThe timer option will be set

在文件 timer.cc49 行定义.

49{ timer_opt_ = opt; }

◆ Start()

void apollo::cyber::Timer::Start ( )

Start the timer

在文件 timer.cc129 行定义.

129 {
130 if (!common::GlobalData::Instance()->IsRealityMode()) {
131 return;
132 }
133
134 if (!started_.exchange(true)) {
135 if (InitTimerTask()) {
136 timing_wheel_->AddTask(task_);
137 AINFO << "start timer [" << task_->timer_id_ << "]";
138 }
139 }
140}
void AddTask(const std::shared_ptr< TimerTask > &task)
#define AINFO
Definition log.h:42

◆ Stop()

void apollo::cyber::Timer::Stop ( )

Stop the timer

在文件 timer.cc142 行定义.

142 {
143 if (started_.exchange(false) && task_) {
144 AINFO << "stop timer, the timer_id: " << timer_id_;
145 // using a shared pointer to hold task_->mutex before task_ reset
146 auto tmp_task = task_;
147 {
148 std::lock_guard<std::mutex> lg(tmp_task->mutex);
149 task_.reset();
150 }
151 }
152}

该类的文档由以下文件生成: