libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
async.hpp
1#pragma once
2
3#include "libxr_cb.hpp"
4#include "libxr_def.hpp"
5#include "semaphore.hpp"
6#include "thread.hpp"
7
8namespace LibXR
9{
10
19class ASync
20{
21 public:
26 enum class Status : uint8_t
27 {
28 REDAY,
29 BUSY,
30 DONE
31 };
32
43
57 static void ThreadFun(ASync *async)
58 {
59 while (true)
60 {
61 if (async->sem_.Wait() == ErrorCode::OK)
62 {
63 async->job_.Run(false, async);
64 async->status_ = Status::DONE;
65 }
66 }
67 }
68
71
85 {
86 if (status_ != Status::DONE)
87 {
88 return status_;
89 }
90 else
91 {
93 return Status::DONE;
94 }
95 }
96
98
111 ErrorCode AssignJob(Callback job);
112
135
139
141};
142
143} // namespace LibXR
异步任务处理类。 Asynchronous task processing class.
Definition async.hpp:20
Status GetStatus()
获取当前异步任务的状态。 Retrieves the current status of the asynchronous task.
Definition async.hpp:84
Status status_
当前异步任务状态。 The current status of the asynchronous task.
Definition async.hpp:69
Status
异步任务的状态枚举。 Enumeration of asynchronous task statuses.
Definition async.hpp:27
@ DONE
任务已完成。 Task is completed.
@ BUSY
任务正在执行中。 Task is currently running.
@ REDAY
任务已准备就绪。 Task is ready.
Thread thread_handle_
处理异步任务的线程。 Thread handling asynchronous tasks.
Definition async.hpp:140
Semaphore sem_
控制任务执行的信号量。 Semaphore controlling task execution.
Definition async.hpp:138
static void ThreadFun(ASync *async)
任务线程函数,等待信号量并执行任务。 Task thread function that waits for a semaphore and executes the assigned job.
Definition async.hpp:57
ErrorCode AssignJob(Callback job)
分配一个异步任务并准备执行。 Assigns an asynchronous job and prepares for execution.
Definition async.cpp:11
Callback job_
存储分配的异步任务回调。 Stores the assigned asynchronous job callback.
Definition async.hpp:137
void AssignJobFromCallback(Callback job, bool in_isr)
在回调环境中分配任务,并通知任务线程执行。 Assigns a job from a callback environment and notifies the task thread.
Definition async.hpp:129
提供一个通用的回调包装,支持动态参数传递。 Provides a generic callback wrapper, supporting dynamic argument passing.
Definition libxr_cb.hpp:125
信号量类,实现线程同步机制 Semaphore class implementing thread synchronization
Definition semaphore.hpp:23
void PostFromCallback(bool in_isr)
从中断回调中释放(增加)信号量 Releases (increments) the semaphore from an ISR (Interrupt Service Routine)
Definition semaphore.cpp:23
线程管理类,封装 FreeRTOS 任务创建和调度 Thread management class encapsulating FreeRTOS task creation and scheduling
Definition thread.hpp:15
Priority
线程优先级枚举 Enumeration for thread priorities
Definition thread.hpp:22
LibXR Color Control Library / LibXR终端颜色控制库
Definition esp_gpio.hpp:8
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值