Contiki-NG
Macros | Typedefs | Functions

This library provides an API and generic implementation of mutexes. More...

Macros

#define mutex_try_lock(m)   mutex_generic_try_lock(m)
 Try to lock a mutex. More...
 
#define mutex_unlock(m)   mutex_generic_unlock(m)
 Unlock a previously acquired mutex. More...
 

Typedefs

typedef uint_fast8_t mutex_t
 Mutex data type. More...
 

Functions

bool mutex_generic_try_lock (volatile mutex_t *mutex)
 Try to lock a mutex. More...
 
void mutex_generic_unlock (volatile mutex_t *mutex)
 Unlock a previously acquired mutex. More...
 

Detailed Description

This library provides an API and generic implementation of mutexes.

Calling code should manipulate mutexes through the mutex_try_lock() and mutex_unlock() macros. By default, those macros will expand to the generic mutex manipulation implementations provided here. While these will work, they do reply on disabling the master interrupt in order to perform the lock/unlock operation.

It is possible to override those generic implementation with CPU-specific implementations that exploit synchronisation instructions. To do so, create a CPU-specific header file. In this file, define mutex_try_lock() and mutex_unlock() to expand to the respective CPU function names. These can (but do not have to) be inlined. Then define MUTEX_CONF_ARCH_HEADER_PATH as this header's filename.

Macro Definition Documentation

◆ mutex_try_lock

#define mutex_try_lock (   m)    mutex_generic_try_lock(m)

Try to lock a mutex.

Parameters
mA pointer to the mutex to be locked
Return values
trueLocking succeeded
falseLocking failed (the mutex is already locked)

This macro will expand to mutex_generic_try_lock() or to a CPU-provided implementation. Platform-independent code should use this macro instead of mutex_generic_try_lock().

Definition at line 91 of file mutex.h.

◆ mutex_unlock

#define mutex_unlock (   m)    mutex_generic_unlock(m)

Unlock a previously acquired mutex.

Parameters
mA pointer to the mutex to be unlocked

This macro will expand to mutex_generic_unlock() or to a CPU-provided implementation. Platform-independent code should use this macro instead of mutex_generic_unlock().

Definition at line 103 of file mutex.h.

Typedef Documentation

◆ mutex_t

typedef uint_fast8_t mutex_t

Mutex data type.

It is possible for the platform to override this with its own typedef. In this scenario, make sure to also define MUTEX_CONF_HAS_MUTEX_T as 1.

Definition at line 77 of file mutex.h.

Function Documentation

◆ mutex_generic_try_lock()

bool mutex_generic_try_lock ( volatile mutex_t mutex)

Try to lock a mutex.

Parameters
mutexA pointer to the mutex to be locked
Return values
trueLocking succeeded
falseLocking failed (the mutex is already locked)

Do not call this function directly. Use the mutex_try_lock() macro instead.

Definition at line 45 of file mutex.c.

◆ mutex_generic_unlock()

void mutex_generic_unlock ( volatile mutex_t mutex)

Unlock a previously acquired mutex.

Parameters
mutexA pointer to the mutex to be unlocked

Do not call this function directly. Use the mutex_unlock() macro instead.

Definition at line 61 of file mutex.c.