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

Functions

int k_futex_wait (struct k_futex *futex, int expected, k_timeout_t timeout)
 Pend the current thread on a futex. More...
 
int k_futex_wake (struct k_futex *futex, bool wake_all)
 Wake one/all threads pending on a futex. More...
 

Detailed Description

Function Documentation

◆ k_futex_wait()

int k_futex_wait ( struct k_futex futex,
int  expected,
k_timeout_t  timeout 
)

#include <include/kernel.h>

Pend the current thread on a futex.

Tests that the supplied futex contains the expected value, and if so, goes to sleep until some other thread calls k_futex_wake() on it.

Parameters
futexAddress of the futex.
expectedExpected value of the futex, if it is different the caller will not wait on it.
timeoutNon-negative waiting period on the futex, or one of the special values K_NO_WAIT or K_FOREVER.
Return values
-EACCESCaller does not have read access to futex address.
-EAGAINIf the futex value did not match the expected parameter.
-EINVALFutex parameter address not recognized by the kernel.
-ETIMEDOUTThread woke up due to timeout and not a futex wakeup.
0if the caller went to sleep and was woken up. The caller should check the futex's value on wakeup to determine if it needs to block again.

◆ k_futex_wake()

int k_futex_wake ( struct k_futex futex,
bool  wake_all 
)

#include <include/kernel.h>

Wake one/all threads pending on a futex.

Wake up the highest priority thread pending on the supplied futex, or wakeup all the threads pending on the supplied futex, and the behavior depends on wake_all.

Parameters
futexFutex to wake up pending threads.
wake_allIf true, wake up all pending threads; If false, wakeup the highest priority thread.
Return values
-EACCESCaller does not have access to the futex address.
-EINVALFutex parameter address not recognized by the kernel.
Numberof threads that were woken up.