Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
Condition Variables APIs

Macros

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

Functions

int k_condvar_init (struct k_condvar *condvar)
 Initialize a condition variable. More...
 
int k_condvar_signal (struct k_condvar *condvar)
 Signals one thread that is pending on the condition variable. More...
 
int k_condvar_broadcast (struct k_condvar *condvar)
 Unblock all threads that are pending on the condition variable. More...
 
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. More...
 

Detailed Description

Macro Definition Documentation

◆ K_CONDVAR_DEFINE

#define K_CONDVAR_DEFINE (   name)

#include <include/kernel.h>

Value:
Z_CONDVAR_INITIALIZER(name)
#define STRUCT_SECTION_ITERABLE(struct_type, name)
Defines a new iterable section.
Definition: common.h:199
Definition: kernel.h:2786

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 <include/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 <include/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 <include/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 <include/kernel.h>

Waits on the condition variable releasing the mutex lock.

Automically 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.