libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
signal.cpp
1#include "signal.hpp"
2
3#include <sys/wait.h>
4#include <unistd.h>
5
6#include <cerrno>
7#include <csignal>
8
9#include "libxr_def.hpp"
10
11using namespace LibXR;
12
13ErrorCode Signal::Action(Thread &thread, int signal) {
15 ASSERT(signal >= SIGRTMIN && signal <= SIGRTMAX);
16
17 if (pthread_kill(thread, signal) == 0) {
18 return ErrorCode::OK;
19 } else {
20 return ErrorCode::FAILED;
21 }
22}
23
25 UNUSED(in_isr);
26 return Action(thread, signal);
27}
28
29ErrorCode Signal::Wait(int signal, uint32_t timeout) {
32 ASSERT(signal >= SIGRTMIN && signal <= SIGRTMAX);
33
37
38 struct timespec ts;
39 ts.tv_sec = timeout / 1000;
40 ts.tv_nsec = static_cast<__syscall_slong_t>((timeout % 1000) * 1000000);
41 int res = sigtimedwait(&waitset, nullptr, &ts);
43 if (res == -1) {
44 if (errno == EAGAIN) {
45 return ErrorCode::TIMEOUT;
46 } else {
47 return ErrorCode::FAILED;
48 }
49 } else {
50 return ErrorCode::OK;
51 }
52}
static ErrorCode Action(Thread &thread, int signal)
触发目标线程的信号处理操作。 Triggers a signal action on the target thread.
Definition signal.cpp:7
static ErrorCode Wait(int signal, uint32_t timeout=UINT32_MAX)
等待指定信号的到来。 Waits for the specified signal.
Definition signal.cpp:35
static ErrorCode ActionFromCallback(Thread &thread, int signal, bool in_isr)
在回调环境中触发目标线程的信号处理操作。 Triggers a signal action on the target thread from a callback environment.
Definition signal.cpp:16
线程管理类,封装 FreeRTOS 任务创建和调度 Thread management class encapsulating FreeRTOS task creation and scheduling
Definition thread.hpp:15
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值