Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
|
Data Structures | |
struct | k_mutex |
Mutex Structure. More... | |
Macros | |
#define | K_MUTEX_DEFINE(name) |
Statically define and initialize a mutex. | |
Functions | |
int | k_mutex_init (struct k_mutex *mutex) |
Initialize a mutex. | |
int | k_mutex_lock (struct k_mutex *mutex, k_timeout_t timeout) |
Lock a mutex. | |
int | k_mutex_unlock (struct k_mutex *mutex) |
Unlock a mutex. | |
#define K_MUTEX_DEFINE | ( | name | ) |
#include <zephyr/kernel.h>
Statically define and initialize a mutex.
The mutex can be accessed outside the module where it is defined using:
name | Name of the mutex. |
int k_mutex_init | ( | struct k_mutex * | mutex | ) |
#include <zephyr/kernel.h>
Initialize a mutex.
This routine initializes a mutex object, prior to its first use.
Upon completion, the mutex is available and does not have an owner.
mutex | Address of the mutex. |
0 | Mutex object created |
int k_mutex_lock | ( | struct k_mutex * | mutex, |
k_timeout_t | timeout ) |
#include <zephyr/kernel.h>
Lock a mutex.
This routine locks mutex. If the mutex is locked by another thread, the calling thread waits until the mutex becomes available or until a timeout occurs.
A thread is permitted to lock a mutex it has already locked. The operation completes immediately and the lock count is increased by 1.
Mutexes may not be locked in ISRs.
mutex | Address of the mutex. |
timeout | Waiting period to lock the mutex, or one of the special values K_NO_WAIT and K_FOREVER. |
0 | Mutex locked. |
-EBUSY | Returned without waiting. |
-EAGAIN | Waiting period timed out. |
int k_mutex_unlock | ( | struct k_mutex * | mutex | ) |
#include <zephyr/kernel.h>
Unlock a mutex.
This routine unlocks mutex. The mutex must already be locked by the calling thread.
The mutex cannot be claimed by another thread until it has been unlocked by the calling thread as many times as it was previously locked by that thread.
Mutexes may not be unlocked in ISRs, as mutexes must only be manipulated in thread context due to ownership and priority inheritance semantics.
mutex | Address of the mutex. |
0 | Mutex unlocked. |
-EPERM | The current thread does not own the mutex |
-EINVAL | The mutex is not locked |