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

Overview

A mutual-exclusion (mutex) object.

Sometimes also referred to as a critical section. Only one thread can take the mutex at a time using lwpa_mutex_take(). Where possible on real-time platforms, the mutex provides priority inheritance.

lwpa_mutex implementations use the following constructs under the hood on various platforms:

On: | lwpa_mutex uses:

Windows | Critical Section objects FreeRTOS/lwIP | Mutexes MQX | Lightweight Semaphores

Typedefs

typedef UNDEFINED lwpa_mutex_t
 The mutex identifier. More...
 

Functions

bool lwpa_mutex_create (lwpa_mutex_t *id)
 Create a new mutex. More...
 
bool lwpa_mutex_take (lwpa_mutex_t *id, int wait_ms)
 Acquire a mutex. More...
 
void lwpa_mutex_give (lwpa_mutex_t *id)
 Release a mutex. More...
 
void lwpa_mutex_destroy (lwpa_mutex_t *id)
 Destroy a mutex object. More...
 

Typedef Documentation

◆ lwpa_mutex_t

typedef UNDEFINED lwpa_mutex_t

The mutex identifier.

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

Function Documentation

◆ lwpa_mutex_create()

bool lwpa_mutex_create ( lwpa_mutex_t id)

Create a new mutex.

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

◆ lwpa_mutex_destroy()

void lwpa_mutex_destroy ( lwpa_mutex_t id)

Destroy a mutex object.

Parameters
[in]idIdentifier for the mutex to destroy.

◆ lwpa_mutex_give()

void lwpa_mutex_give ( lwpa_mutex_t id)

Release a mutex.

Parameters
[in]idIdentifier for the mutex to release.

◆ lwpa_mutex_take()

bool lwpa_mutex_take ( lwpa_mutex_t id,
int  wait_ms 
)

Acquire a mutex.

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