Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
User mode mutex APIs

Macros

#define SYS_MUTEX_DEFINE(name)    struct sys_mutex name
 Statically define and initialize a sys_mutex. More...
 

Functions

static void sys_mutex_init (struct sys_mutex *mutex)
 Initialize a mutex. More...
 
static int sys_mutex_lock (struct sys_mutex *mutex, k_timeout_t timeout)
 Lock a mutex. More...
 
static int sys_mutex_unlock (struct sys_mutex *mutex)
 Unlock a mutex. More...
 

Detailed Description

Macro Definition Documentation

◆ SYS_MUTEX_DEFINE

#define SYS_MUTEX_DEFINE (   name)     struct sys_mutex name

#include <include/sys/mutex.h>

Statically define and initialize a sys_mutex.

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

extern struct sys_mutex <name>;
Definition: mutex.h:28

Route this to memory domains using K_APP_DMEM().

Parameters
nameName of the mutex.

Function Documentation

◆ sys_mutex_init()

static void sys_mutex_init ( struct sys_mutex mutex)
inlinestatic

#include <include/sys/mutex.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.

This routine is only necessary to call when userspace is disabled and the mutex was not created with SYS_MUTEX_DEFINE().

Parameters
mutexAddress of the mutex.
Returns
N/A

◆ sys_mutex_lock()

static int sys_mutex_lock ( struct sys_mutex mutex,
k_timeout_t  timeout 
)
inlinestatic

#include <include/sys/mutex.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.

Parameters
mutexAddress of the mutex, which may reside in user memory
timeoutWaiting period to lock the mutex, or one of the special values K_NO_WAIT and K_FOREVER.
Return values
0Mutex locked.
-EBUSYReturned without waiting.
-EAGAINWaiting period timed out.
-EACCESCaller has no access to provided mutex address
-EINVALProvided mutex not recognized by the kernel

◆ sys_mutex_unlock()

static int sys_mutex_unlock ( struct sys_mutex mutex)
inlinestatic

#include <include/sys/mutex.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.

Parameters
mutexAddress of the mutex, which may reside in user memory
Return values
0Mutex unlocked
-EACCESCaller has no access to provided mutex address
-EINVALProvided mutex not recognized by the kernel or mutex wasn't locked
-EPERMCaller does not own the mutex