picofuse

Macros | Typedefs
Condition Variables
Collaboration diagram for Condition Variables:

Macros

#define SYS_COND_CAPACITY   32
 Maximum number of condition variables available in static-pool implementations.
 

Typedefs

typedef struct sys_cond_t sys_cond_t
 Condition variable.
 

Lifecycle

sys_cond_tsys_cond_init (void)
 Initialize a new condition variable. More...
 
void sys_cond_deinit (sys_cond_t *cond)
 Deinitialize a condition variable. More...
 

Methods

bool sys_cond_wait (sys_cond_t *cond, sys_mutex_t *mutex)
 Wait on a condition variable. More...
 
bool sys_cond_timedwait (sys_cond_t *cond, sys_mutex_t *mutex, uint32_t timeout_ms)
 Wait on a condition variable with timeout. More...
 
bool sys_cond_signal (sys_cond_t *cond)
 Signal one waiting thread. More...
 
bool sys_cond_broadcast (sys_cond_t *cond)
 Signal all waiting threads. More...
 

Detailed Description

Function Documentation

◆ sys_cond_broadcast()

bool sys_cond_broadcast ( sys_cond_t cond)

Signal all waiting threads.

Parameters
condPointer to the condition variable to broadcast
Returns
true if successful, false on error

Wakes up all threads waiting on the condition variable. If no threads are waiting, this function has no effect. The associated mutex should be locked when calling this function for predictable behavior.

◆ sys_cond_deinit()

void sys_cond_deinit ( sys_cond_t cond)

Deinitialize a condition variable.

Parameters
condPointer to the condition variable to deinitialize

Releases all resources associated with the condition variable and renders it unusable. No threads should be waiting on the condition variable when this function is called.

◆ sys_cond_init()

sys_cond_t* sys_cond_init ( void  )

Initialize a new condition variable.

Returns
Initialized condition variable structure

Creates and initializes a new condition variable for thread synchronization. The condition variable is ready for use with wait/signal operations. The returned condition variable must be deinitialized with sys_cond_deinit()

◆ sys_cond_signal()

bool sys_cond_signal ( sys_cond_t cond)

Signal one waiting thread.

Parameters
condPointer to the condition variable to signal
Returns
true if successful, false on error

Wakes up one thread waiting on the condition variable. If no threads are waiting, this function has no effect. The associated mutex should be locked when calling this function for predictable behavior.

◆ sys_cond_timedwait()

bool sys_cond_timedwait ( sys_cond_t cond,
sys_mutex_t mutex,
uint32_t  timeout_ms 
)

Wait on a condition variable with timeout.

Parameters
condPointer to the condition variable to wait on
mutexPointer to the mutex that must be locked by the calling thread
timeout_msTimeout in milliseconds (0 = no timeout)
Returns
true if signaled, false if timeout or error

Like sys_cond_wait() but returns after timeout_ms milliseconds if not signaled. Returns true if signaled, false if timeout or error occurred.

◆ sys_cond_wait()

bool sys_cond_wait ( sys_cond_t cond,
sys_mutex_t mutex 
)

Wait on a condition variable.

Parameters
condPointer to the condition variable to wait on
mutexPointer to the mutex that must be locked by the calling thread
Returns
true if the wait completed successfully, false on error

Atomically releases the mutex and waits for the condition variable to be signaled. Upon return, the mutex is reacquired. The mutex must be locked by the calling thread before calling this function.