3#include "libxr_def.hpp"
4#include "lockfree_list.hpp"
66 template <
typename ArgType>
79 Data *data =
new Data;
83 data->ctrl_block.data_.handle = data;
84 data->ctrl_block.data_.fun_ = [](
void *arg)
86 Data *data =
reinterpret_cast<Data *
>(arg);
89 data->ctrl_block.data_.count_ = 0;
90 data->ctrl_block.data_.cycle_ = cycle;
91 data->ctrl_block.data_.enable_ =
false;
93 return &data->ctrl_block;
数据节点模板,继承自 BaseNode,用于存储具体数据类型。 Template data node that inherits from BaseNode to store specific data...
链表实现,用于存储和管理数据节点。 A linked list implementation for storing and managing data nodes.
线程管理类,封装 POSIX 线程创建和调度 Thread management class encapsulating POSIX thread creation and scheduling
Priority
线程优先级枚举 Enumeration for thread priorities
@ MEDIUM
中等优先级 Medium priority
控制块类,存储任务信息 Control block class for storing task information
void Run()
运行定时任务 Runs the scheduled task
uint32_t cycle_
任务周期(单位:毫秒) Task cycle (unit: milliseconds)
void * handle
任务句柄 Handle to the task
uint32_t count_
计数器 Counter
bool enable_
任务是否启用 Flag indicating whether the task is enabled
void(* fun_)(void *)
任务执行函数 Function pointer to the task
定时器类,实现周期性任务调度 Timer class for scheduling periodic tasks
static Thread thread_handle_
定时器管理线程 Timer management thread
static uint32_t stack_depth_
线程栈深度 Thread stack depth
static void RefreshTimerInIdle()
在空闲时刷新定时器 Refreshes the timer during idle time
static LibXR::Thread::Priority priority_
线程优先级 Thread priority
static void RefreshThreadFunction(void *)
定时器管理线程函数 Timer management thread function
LibXR::LockFreeList::Node< ControlBlock > * TimerHandle
定时器任务句柄 Timer task handle
static void Refresh()
刷新定时任务状态 Refreshes the state of periodic tasks
static TimerHandle CreateTask(void(*fun)(ArgType), ArgType arg, uint32_t cycle)
创建定时任务 Creates a periodic task
static void SetCycle(TimerHandle handle, uint32_t cycle)
设置定时任务的周期 Sets the cycle of a periodic task
static void Start(TimerHandle handle)
启动定时任务 Starts a periodic task
static void Add(TimerHandle handle)
添加定时任务 Adds a periodic task
static LibXR::LockFreeList * list_
定时任务列表 List of registered tasks
static void Stop(TimerHandle handle)
停止定时任务 Stops a periodic task