|
libxr
1.0
Want to be the best embedded framework
|
异步任务处理类。 Asynchronous task processing class. More...
#include <async.hpp>
Public Types | |
| enum class | Status : uint32_t { READY = 0 , BUSY = 1 , DONE = UINT32_MAX } |
| 异步任务的状态枚举。 Enumeration of asynchronous task statuses. More... | |
| using | Job = LibXR::Callback<ASync *> |
Public Member Functions | |
| ASync (size_t stack_depth, Thread::Priority priority) | |
构造 ASync 对象并初始化任务线程。 Constructs an ASync object and initializes the task thread. | |
| Status | GetStatus () |
| 获取当前异步任务的状态。 Retrieves the current status of the asynchronous task. | |
| ErrorCode | AssignJob (Job job) |
| 分配一个异步任务并准备执行。 Assigns an asynchronous job and prepares for execution. | |
| void | AssignJobFromCallback (Job job, bool in_isr) |
| 在回调环境中分配任务,并通知任务线程执行。 Assigns a job from a callback environment and notifies the task thread. | |
Static Public Member Functions | |
| static void | ThreadFun (ASync *async) |
| 任务线程函数,等待信号量并执行任务。 Task thread function that waits for a semaphore and executes the assigned job. | |
Data Fields | |
| std::atomic< Status > | status_ = Status::READY |
| 当前异步任务状态 | |
| Job | job_ |
| 存储分配的异步任务回调。 Stores the assigned asynchronous job callback. | |
| Semaphore | sem_ |
| 控制任务执行的信号量。 Semaphore controlling task execution. | |
| Thread | thread_handle_ |
| 处理异步任务的线程。 Thread handling asynchronous tasks. | |
异步任务处理类。 Asynchronous task processing class.
该类用于管理异步任务的执行,提供任务分配、状态管理以及线程执行功能。 This class manages the execution of asynchronous tasks, providing task assignment, status management, and thread execution functionalities.
| using LibXR::ASync::Job = LibXR::Callback<ASync *> |
|
strong |
| ASync::ASync | ( | size_t | stack_depth, |
| Thread::Priority | priority ) |
构造 ASync 对象并初始化任务线程。 Constructs an ASync object and initializes the task thread.
| stack_depth | 线程栈深度。 Stack depth for the thread. |
| priority | 线程优先级。 Priority of the thread. |
Definition at line 8 of file async.cpp.
| ErrorCode ASync::AssignJob | ( | Job | job | ) |
分配一个异步任务并准备执行。 Assigns an asynchronous job and prepares for execution.
该函数用于设置 job_ 回调,并将任务状态置为 BUSY。 This function sets the job_ callback and updates the task status to BUSY.
| job | 需要执行的回调任务。 The callback job to be executed. |
ErrorCode,指示操作是否成功。 Returns an ErrorCode indicating whether the operation was successful. Definition at line 13 of file async.cpp.
|
inline |
在回调环境中分配任务,并通知任务线程执行。 Assigns a job from a callback environment and notifies the task thread.
该函数适用于中断上下文或回调环境, 直接修改 job_ 并设置状态为 BUSY,然后通过信号量通知任务线程。 This function is designed for use in an interrupt context or callback environment, directly modifying job_, setting the status to BUSY, and signaling the task thread via a semaphore.
| job | 需要执行的回调任务。 The callback job to be executed. |
| in_isr | 是否在中断上下文中调用。 Indicates whether the function is called within an interrupt service routine. |
Definition at line 128 of file async.hpp.
|
inlinenodiscard |
获取当前异步任务的状态。 Retrieves the current status of the asynchronous task.
如果任务尚未完成,则返回当前 status_。 如果任务已完成,则返回 DONE 并重置状态为 READY。 If the task is not yet completed, it returns the current status_. If the task is completed, it returns DONE and resets the status to READY.
Definition at line 85 of file async.hpp.
|
inlinestatic |
任务线程函数,等待信号量并执行任务。 Task thread function that waits for a semaphore and executes the assigned job.
该函数作为 ASync 任务的主线程,持续等待 sem_ 释放后执行任务, 执行完成后更新 status_ 状态。 This function serves as the main thread for ASync, continuously waiting for sem_ to be released before executing a job, and updating status_ upon completion.
Definition at line 59 of file async.hpp.
| Job LibXR::ASync::job_ |
| Semaphore LibXR::ASync::sem_ |
| std::atomic<Status> LibXR::ASync::status_ = Status::READY |
| Thread LibXR::ASync::thread_handle_ |