6#include "libxr_def.hpp"
7#include "semaphore.hpp"
63 if (async->
sem_.
Wait() == ErrorCode::OK)
异步任务处理类。 Asynchronous task processing class.
std::atomic< Status > status_
当前异步任务状态
Status GetStatus()
获取当前异步任务的状态。 Retrieves the current status of the asynchronous task.
void AssignJobFromCallback(Job job, bool in_isr)
在回调环境中分配任务,并通知任务线程执行。 Assigns a job from a callback environment and notifies the task thread.
Job job_
存储分配的异步任务回调。 Stores the assigned asynchronous job callback.
ErrorCode AssignJob(Job job)
分配一个异步任务并准备执行。 Assigns an asynchronous job and prepares for execution.
Thread thread_handle_
处理异步任务的线程。 Thread handling asynchronous tasks.
ASync(size_t stack_depth, Thread::Priority priority)
构造 ASync 对象并初始化任务线程。 Constructs an ASync object and initializes the task thread.
Semaphore sem_
控制任务执行的信号量。 Semaphore controlling task execution.
static void ThreadFun(ASync *async)
任务线程函数,等待信号量并执行任务。 Task thread function that waits for a semaphore and executes the assigned job.
Status
异步任务的状态枚举。 Enumeration of asynchronous task statuses.
@ DONE
任务已完成。 Task is completed.
@ READY
任务已准备就绪。 Task is ready.
@ BUSY
任务正在执行中。 Task is currently running.
提供一个通用的回调包装,支持动态参数传递。 Provides a generic callback wrapper, supporting dynamic argument passing.
void Run(bool in_isr, PassArgs &&...args) const
执行回调函数,并传递参数。 Executes the callback function, passing the arguments.
信号量类,实现线程同步机制 Semaphore class implementing thread synchronization
void PostFromCallback(bool in_isr)
从中断回调中释放(增加)信号量 Releases (increments) the semaphore from an ISR (Interrupt Service Routine)
ErrorCode Wait(uint32_t timeout=UINT32_MAX)
等待(减少)信号量 Waits (decrements) the semaphore
线程管理类,封装 POSIX 线程创建和调度 Thread management class encapsulating POSIX thread creation and scheduling
Priority
线程优先级枚举 Enumeration for thread priorities