libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
async.cpp
1#include "async.hpp"
2
3#include "libxr_def.hpp"
4#include "thread.hpp"
5
6using namespace LibXR;
7
10}
11
12ErrorCode ASync::AssignJob(Callback job) {
13 if (status_ == Status::BUSY) {
14 return ErrorCode::BUSY;
15 }
16
18
19 job_ = job;
20 sem_.Post();
21
22 return ErrorCode::OK;
23}
Status status_
当前异步任务状态。 The current status of the asynchronous task.
Definition async.hpp:69
@ BUSY
任务正在执行中。 Task is currently running.
Thread thread_handle_
处理异步任务的线程。 Thread handling asynchronous tasks.
Definition async.hpp:140
ASync(size_t stack_depth, Thread::Priority priority)
构造 ASync 对象并初始化任务线程。 Constructs an ASync object and initializes the task thread.
Definition async.cpp:7
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
提供一个通用的回调包装,支持动态参数传递。 Provides a generic callback wrapper, supporting dynamic argument passing.
Definition libxr_cb.hpp:125
void Post()
释放(增加)信号量 Releases (increments) the semaphore
Definition semaphore.cpp:13
Priority
线程优先级枚举 Enumeration for thread priorities
Definition thread.hpp:22
void Create(ArgType arg, void(*function)(ArgType arg), const char *name, size_t stack_depth, Thread::Priority priority)
创建新线程 Creates a new thread
Definition thread.hpp:64
LibXR Color Control Library / LibXR终端颜色控制库
Definition esp_gpio.hpp:8
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值