nRF5 SDK v15.2.0
Macros | Typedefs | Functions

Mutex used for protecting resources. More...

Macros

#define NRF_MTX_LOCKED   1
 
#define NRF_MTX_UNLOCKED   0
 

Typedefs

typedef nrf_atomic_u32_t nrf_mtx_t
 Mutex data type. More...
 

Functions

__STATIC_INLINE void nrf_mtx_init (nrf_mtx_t *p_mtx)
 Initialize mutex. More...
 
__STATIC_INLINE void nrf_mtx_destroy (nrf_mtx_t *p_mtx)
 Destroy mutex. More...
 
__STATIC_INLINE bool nrf_mtx_trylock (nrf_mtx_t *p_mtx)
 Try to lock a mutex. More...
 
__STATIC_INLINE void nrf_mtx_unlock (nrf_mtx_t *p_mtx)
 Unlock a mutex. More...
 

Detailed Description

Mutex used for protecting resources.

This module provides a mutex that can be used to ensure only one context may enter a critical section holding the lock.

Typedef Documentation

Mutex data type.

All fields in this struct are internal, and should never be modified outside of the nrf_mtx_* functions.

Function Documentation

__STATIC_INLINE void nrf_mtx_destroy ( nrf_mtx_t p_mtx)

Destroy mutex.

This function can be used in abort scenarios or when the mutex is no longer to be used.

Parameters
[in]p_mtxThe mutex to be destroy.
__STATIC_INLINE void nrf_mtx_init ( nrf_mtx_t p_mtx)

Initialize mutex.

This function must be called before nrf_mtx_trylock() and nrf_mtx_unlock() functions.

Parameters
[in,out]p_mtxThe mutex to be initialized.
__STATIC_INLINE bool nrf_mtx_trylock ( nrf_mtx_t p_mtx)

Try to lock a mutex.

If the mutex is already held by another context, this function will return immediately.

Parameters
[in,out]p_mtxThe mutex to be locked.
Returns
true if lock was acquired, false if not
__STATIC_INLINE void nrf_mtx_unlock ( nrf_mtx_t p_mtx)

Unlock a mutex.

This function must only be called when holding the lock. Unlocking a mutex which you do not hold will give undefined behavior.

Note
Unlock must happen from the same context as the one used to lock the mutex.
Parameters
[in,out]p_mtxThe mutex to be unlocked.

Documentation feedback | Developer Zone | Subscribe | Updated