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
8ASync::ASync(size_t stack_depth, Thread::Priority priority)
9{
10 thread_handle_.Create(this, ThreadFun, "async_job", stack_depth, priority);
11}
12
13ErrorCode ASync::AssignJob(Job job)
14{
15 Status expected = Status::READY;
16 if (!status_.compare_exchange_strong(expected, Status::BUSY))
17 {
18 return ErrorCode::BUSY;
19 }
20
21 job_ = job;
22 sem_.Post();
23
24 return ErrorCode::OK;
25}
std::atomic< Status > status_
当前异步任务状态
Definition async.hpp:71
Job job_
存储分配的异步任务回调。 Stores the assigned asynchronous job callback.
Definition async.hpp:135
ErrorCode AssignJob(Job job)
分配一个异步任务并准备执行。 Assigns an asynchronous job and prepares for execution.
Definition async.cpp:13
Status
异步任务的状态枚举。 Enumeration of asynchronous task statuses.
Definition async.hpp:29
@ READY
任务已准备就绪。 Task is ready.
@ BUSY
任务正在执行中。 Task is currently running.
Thread thread_handle_
处理异步任务的线程。 Thread handling asynchronous tasks.
Definition async.hpp:138
ASync(size_t stack_depth, Thread::Priority priority)
构造 ASync 对象并初始化任务线程。 Constructs an ASync object and initializes the task thread.
Definition async.cpp:8
Semaphore sem_
控制任务执行的信号量。 Semaphore controlling task execution.
Definition async.hpp:136
static void ThreadFun(ASync *async)
任务线程函数,等待信号量并执行任务。 Task thread function that waits for a semaphore and executes the assigned job.
Definition async.hpp:59
void Post()
释放(增加)信号量 Releases (increments) the semaphore
Definition semaphore.cpp:23
Priority
线程优先级枚举 Enumeration for thread priorities
Definition thread.hpp:21
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 命名空间
Definition ch32_gpio.hpp:9