Zephyr API Documentation 3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Condition Variables APIs

Macros

#define K_CONDVAR_DEFINE(name)
 Statically define and initialize a condition variable.
 

Functions

int k_condvar_init (struct k_condvar *condvar)
 Initialize a condition variable.
 
int k_condvar_signal (struct k_condvar *condvar)
 Signals one thread that is pending on the condition variable.
 
int k_condvar_broadcast (struct k_condvar *condvar)
 Unblock all threads that are pending on the condition variable.
 
int k_condvar_wait (struct k_condvar *condvar, struct k_mutex *mutex, k_timeout_t timeout)
 Waits on the condition variable releasing the mutex lock.
 

Detailed Description

Macro Definition Documentation

◆ K_CONDVAR_DEFINE

#define K_CONDVAR_DEFINE ( name)

#include <zephyr/kernel.h>

Value:
Z_CONDVAR_INITIALIZER(name)
#define STRUCT_SECTION_ITERABLE(struct_type, varname)
Defines a new element for an iterable section.
Definition iterable_sections.h:216
Definition kernel.h:3106

Statically define and initialize a condition variable.

The condition variable can be accessed outside the module where it is defined using:

extern struct k_condvar <name>;
Parameters
nameName of the condition variable.

Function Documentation

◆ k_condvar_broadcast()

int k_condvar_broadcast ( struct k_condvar * condvar)

#include <zephyr/kernel.h>

Unblock all threads that are pending on the condition variable.

Parameters
condvarpointer to a k_condvar structure
Returns
An integer with number of woken threads on success

◆ k_condvar_init()

int k_condvar_init ( struct k_condvar * condvar)

#include <zephyr/kernel.h>

Initialize a condition variable.

Parameters
condvarpointer to a k_condvar structure
Return values
0Condition variable created successfully

◆ k_condvar_signal()

int k_condvar_signal ( struct k_condvar * condvar)

#include <zephyr/kernel.h>

Signals one thread that is pending on the condition variable.

Parameters
condvarpointer to a k_condvar structure
Return values
0On success

◆ k_condvar_wait()

int k_condvar_wait ( struct k_condvar * condvar,
struct k_mutex * mutex,
k_timeout_t timeout )

#include <zephyr/kernel.h>

Waits on the condition variable releasing the mutex lock.

Atomically releases the currently owned mutex, blocks the current thread waiting on the condition variable specified by condvar, and finally acquires the mutex again.

The waiting thread unblocks only after another thread calls k_condvar_signal, or k_condvar_broadcast with the same condition variable.

Parameters
condvarpointer to a k_condvar structure
mutexAddress of the mutex.
timeoutWaiting period for the condition variable or one of the special values K_NO_WAIT and K_FOREVER.
Return values
0On success
-EAGAINWaiting period timed out.