lwpa  0.1.0
LightWeight Platform Abstraction (lwpa)
View other versions:
lwpa_signal

Overview

A signal object.

Sometimes also referred to as a binary semaphore or event. Used for thread synchronization; a call to lwpa_signal_wait() blocks until lwpa_signal_post() is called.

Typedefs

typedef UNDEFINED lwpa_signal_t
 The signal identifier. More...
 

Functions

bool lwpa_signal_create (lwpa_signal_t *id)
 Create a new signal. More...
 
bool lwpa_signal_wait (lwpa_signal_t *id, int wait_ms)
 Wait for a signal. More...
 
void lwpa_signal_post (lwpa_signal_t *id)
 Post a signal. More...
 
void lwpa_signal_destroy (lwpa_signal_t *id)
 Destroy a signal object. More...
 

Typedef Documentation

◆ lwpa_signal_t

typedef UNDEFINED lwpa_signal_t

The signal identifier.

Depending on the platform, this could be a scalar type or a struct.

Function Documentation

◆ lwpa_signal_create()

bool lwpa_signal_create ( lwpa_signal_t id)

Create a new signal.

Signals are created in the "unsignaled" state; that is, the first call to lwpa_signal_wait() will block.

Parameters
[in,out]idSignal identifier on which to create a signal. If this function returns true, id becomes valid for calls to lwpa_signal_wait() and lwpa_signal_post().
Returns
true (the signal was created) or false (the signal was not created).

◆ lwpa_signal_destroy()

void lwpa_signal_destroy ( lwpa_signal_t id)

Destroy a signal object.

Parameters
[in]idIdentifier for the signal to destroy.

◆ lwpa_signal_post()

void lwpa_signal_post ( lwpa_signal_t id)

Post a signal.

If no threads are waiting for the signal, puts the signal object in the "signaled" state (a subsequent call to lwpa_signal_wait() will return immediately). Otherwise, wakes up the first thread that waited for the signal.

Parameters
[in]idIdentifier for the signal to post.

◆ lwpa_signal_wait()

bool lwpa_signal_wait ( lwpa_signal_t id,
int  wait_ms 
)

Wait for a signal.

If this is the first call to lwpa_signal_wait() after the signal object has been posted via lwpa_signal_post(), returns immediately. Otherwise, blocks until a call to lwpa_signal_post() on the signal object.

Parameters
[in]idIdentifier for the signal for which to wait.
[in]wait_msHow long to wait for the signal, in milliseconds (use LWPA_WAIT_FOREVER to wait indefinitely).
Returns
true (the signal was received) or false (timeout or failure while waiting for the signal).