libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::Signal Class Reference

信号处理类,用于线程间的信号传递和同步。 Signal handling class for inter-thread signaling and synchronization. More...

#include <signal.hpp>

Static Public Member Functions

static ErrorCode Action (Thread &thread, int signal)
 触发目标线程的信号处理操作。 Triggers a signal action on the target thread.
 
static ErrorCode ActionFromCallback (Thread &thread, int signal, bool in_isr)
 在回调环境中触发目标线程的信号处理操作。 Triggers a signal action on the target thread from a callback environment.
 
static ErrorCode Wait (int signal, uint32_t timeout=UINT32_MAX)
 等待指定信号的到来。 Waits for the specified signal.
 

Detailed Description

信号处理类,用于线程间的信号传递和同步。 Signal handling class for inter-thread signaling and synchronization.

该类提供信号的发送、回调环境中的信号发送以及线程等待信号的功能, 主要用于线程间的通信和同步。 This class provides functionalities for sending signals, sending signals from a callback environment, and waiting for signals, primarily used for inter-thread communication and synchronization.

Definition at line 19 of file signal.hpp.

Member Function Documentation

◆ Action()

ErrorCode Signal::Action ( Thread thread,
int  signal 
)
static

触发目标线程的信号处理操作。 Triggers a signal action on the target thread.

该函数用于向指定线程 thread 发送信号 signal, 使其执行相应的信号处理逻辑。 This function sends the signal signal to the specified thread thread, triggering its corresponding signal handling logic.

Parameters
thread目标线程对象。 The target thread object.
signal需要触发的信号。 The signal to be triggered.
Returns
返回 ErrorCode,指示操作是否成功。 Returns an ErrorCode indicating whether the operation was successful.

Definition at line 7 of file signal.cpp.

7 {
9 pdPASS) {
10 return ErrorCode::OK;
11 } else {
12 return ErrorCode::FAILED;
13 }
14}
TaskHandle_t libxr_thread_handle
线程句柄类型定义 Thread handle type definition
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值

◆ ActionFromCallback()

ErrorCode Signal::ActionFromCallback ( Thread thread,
int  signal,
bool  in_isr 
)
static

在回调环境中触发目标线程的信号处理操作。 Triggers a signal action on the target thread from a callback environment.

该函数适用于中断或回调环境,可安全地向指定线程 thread 发送信号 signal。 This function is designed for use in an interrupt or callback environment, safely sending the signal signal to the specified thread thread.

Parameters
thread目标线程对象。 The target thread object.
signal需要触发的信号。 The signal to be triggered.
in_isr指示是否在中断上下文中调用。 Indicates whether the function is called within an interrupt service routine.
Returns
返回 ErrorCode,指示操作是否成功。 Returns an ErrorCode indicating whether the operation was successful.

Definition at line 16 of file signal.cpp.

16 {
17 if (in_isr) {
23 portYIELD(); // NOLINT
24 }
25 if (ans == pdPASS) {
26 return ErrorCode::OK;
27 } else {
28 return ErrorCode::FAILED;
29 }
30 } else {
31 return Action(thread, signal);
32 }
33}
static ErrorCode Action(Thread &thread, int signal)
触发目标线程的信号处理操作。 Triggers a signal action on the target thread.
Definition signal.cpp:7

◆ Wait()

ErrorCode Signal::Wait ( int  signal,
uint32_t  timeout = UINT32_MAX 
)
static

等待指定信号的到来。 Waits for the specified signal.

该函数阻塞调用线程,直到接收到 signal 或者超时。 This function blocks the calling thread until it receives signal or times out.

Parameters
signal等待的信号编号。 The signal number to wait for.
timeout等待超时时间(默认为 UINT32_MAX,表示无限等待)。 The timeout duration (default is UINT32_MAX, meaning infinite wait).
Returns
返回 ErrorCode,指示操作是否成功。 Returns an ErrorCode indicating whether the operation was successful.

Definition at line 35 of file signal.cpp.

35 {
36 ASSERT(signal >= 0 && signal < 32);
37
38 uint32_t value = 0;
40
41 const uint32_t SIG_BIT = 1 << signal;
42
43 if ((value & SIG_BIT) == SIG_BIT) {
44 value &= ~SIG_BIT;
46 return ErrorCode::OK;
47 } else {
48 if (timeout == 0) {
49 return ErrorCode::TIMEOUT;
50 }
51 }
52
54
55 while (xTaskNotifyWait(0, SIG_BIT, &value, timeout) == pdPASS) {
56 if ((value & SIG_BIT) == SIG_BIT) {
57 return ErrorCode::OK;
58 }
59
61
62 if (now - current_time >= timeout) {
63 return ErrorCode::TIMEOUT;
64 }
65
66 timeout -= now - current_time;
67 }
68
69 return ErrorCode::FAILED;
70}

The documentation for this class was generated from the following files: