|
template<typename ArgType > |
static TimerHandle | CreateTask (void(*fun)(ArgType), ArgType arg, uint32_t cycle) |
| 创建定时任务 Creates a periodic task
|
|
static void | Start (TimerHandle handle) |
| 启动定时任务 Starts a periodic task
|
|
static void | Stop (TimerHandle handle) |
| 停止定时任务 Stops a periodic task
|
|
static void | SetCycle (TimerHandle handle, uint32_t cycle) |
| 设置定时任务的周期 Sets the cycle of a periodic task
|
|
static void | RefreshThreadFunction (void *) |
| 定时器管理线程函数 Timer management thread function
|
|
static void | Remove (TimerHandle handle) |
| 删除定时任务 Removes a periodic task
|
|
static void | Add (TimerHandle handle) |
| 添加定时任务 Adds a periodic task
|
|
static void | Refresh () |
| 刷新定时任务状态 Refreshes the state of periodic tasks
|
|
static void | RefreshTimerInIdle () |
| 在空闲时刷新定时器 Refreshes the timer during idle time
|
|
定时器类,实现周期性任务调度 Timer class for scheduling periodic tasks
该定时器支持多任务调度,可用于执行周期性任务,如定时回调函数调用。 Timer 提供任务创建、启动、停止、删除及周期调整等功能,并使用 Thread::SleepUntil
实现精确调度。
This timer supports multi-task scheduling and can be used to execute periodic tasks, such as invoking callback functions at regular intervals. It provides task creation, start, stop, delete, and cycle adjustment functionalities, utilizing Thread::SleepUntil
for precise scheduling.
Definition at line 26 of file timer.hpp.
template<typename ArgType >
static TimerHandle LibXR::Timer::CreateTask |
( |
void(* | fun )(ArgType), |
|
|
ArgType | arg, |
|
|
uint32_t | cycle ) |
|
inlinestaticnodiscard |
创建定时任务 Creates a periodic task
- Template Parameters
-
ArgType | 任务参数类型 Type of task argument |
- Parameters
-
fun | 定时执行的任务函数 Function to execute periodically |
arg | 任务参数 Argument for the function |
cycle | 任务周期(毫秒) Task execution cycle (milliseconds) |
- Returns
- 任务句柄 TimerHandle pointing to the created task
该方法创建一个新的周期性任务,任务将在 cycle
毫秒的周期内运行。 若 cycle
小于等于 0,则会触发 ASSERT
断言。
This method creates a new periodic task that runs in a cycle of cycle
milliseconds. If cycle
is less than or equal to 0, it triggers an ASSERT
assertion.
Definition at line 69 of file timer.hpp.
71 {
72 ASSERT(cycle > 0);
73
74 typedef struct
75 {
77 ArgType arg;
78 void (*fun)(ArgType);
79 } Data;
80
81 Data *data = new Data;
82 data->fun = fun;
83 data->arg = arg;
84
85 data->ctrl_block.data_.handle = data;
86 data->ctrl_block.data_.fun_ = [](void *arg)
87 {
88 Data *data = reinterpret_cast<Data *>(arg);
89 data->fun(data->arg);
90 };
91 data->ctrl_block.data_.count_ = 0;
92 data->ctrl_block.data_.cycle_ = cycle;
93 data->ctrl_block.data_.enable_ = false;
94
95 return &data->ctrl_block;
96 }
数据节点模板,继承自 BaseNode,用于存储具体数据类型。 Template data node that inherits from BaseNode to store specific data...