EtcPal  HEAD (unstable)
ETC Platform Abstraction Layer (EtcPal)
View other versions:
Signal Class Reference

Overview

A wrapper class for the EtcPal signal type.

Example usage:

std::string data;
void worker_thread()
{
// Wait until main() sends data
sig.Wait();
std::cout << "Worker thread is processing data\n";
data += " after processing";
// Send data back to main()
std::cout << "Worker thread signals data processing completed\n";
sig.Notify();
}
int main()
{
etcpal::Thread worker(worker_thread);
data = "Example data";
// send data to the worker thread
std::cout << "main() signals data ready for processing\n";
sig.Notify();
// wait for the worker
sig.Wait();
std::cout << "Back in main(), data = " << data << '\n';
worker.Join();
return 0;
}
A wrapper class for the EtcPal signal type.
Definition: signal.h:89
void Notify()
Notify those waiting on the signal.
Definition: signal.h:146
bool Wait()
Wait for the signal.
Definition: signal.h:124
A thread class, modeled after std::thread.
Definition: thread.h:146

The output of the above would be:

main() signals data ready for processing
Worker thread is processing data
Worker thread signals data processing completed
Back in main(), data = Example data after processing

See signal (Signals) for more information.

Public Member Functions

 Signal ()
 Create a new signal.
 
 ~Signal ()
 Destroy the signal.
 
 Signal (const Signal &other)=delete
 
Signaloperator= (const Signal &other)=delete
 
 Signal (Signal &&other)=delete
 
Signaloperator= (Signal &&other)=delete
 
bool Wait ()
 Wait for the signal. More...
 
bool TryWait (int timeout_ms=0)
 Wait for the signal until either it is received or a timeout expires. More...
 
void Notify ()
 Notify those waiting on the signal. More...
 
void NotifyFromIsr ()
 Notify those waiting on the signal from an interrupt context. More...
 
etcpal_signal_tget ()
 Get a reference to the underlying etcpal_signal_t type.
 

Member Function Documentation

◆ Notify()

void Notify ( )
inline

Notify those waiting on the signal.

See etcpal_signal_post().

◆ NotifyFromIsr()

void NotifyFromIsr ( )
inline

Notify those waiting on the signal from an interrupt context.

NOTE: Only meaningful on some platforms. See the table in signal (Signals) and etcpal_signal_post_from_isr() for more information. On platforms on which it is not meaningful, executes the equivalent of Notify().

◆ TryWait()

bool TryWait ( int  timeout_ms = 0)
inline

Wait for the signal until either it is received or a timeout expires.

NOTE: Timeouts other than 0 or ETCPAL_WAIT_FOREVER are typically only honored on real-time platforms. See the table in signal (Signals) for more information. On platforms where timeouts are not honored, passing 0 for timeout_ms returns immediately whether the signal is in the signaled or unsignaled state, while any other value executes the equivalent of Wait().

Parameters
timeout_msHow long to wait for the signal, in milliseconds.
Returns
The result of etcpal_signal_timed_wait() on the underlying signal.

◆ Wait()

bool Wait ( )
inline

Wait for the signal.

Returns
The result of etcpal_signal_wait() on the underlying signal.

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