nRF5 SDK v17.1.0
Macros | Typedefs | Functions

Mutex used for protecting resources. More...


#define NRF_MTX_LOCKED   1
#define NRF_MTX_UNLOCKED   0


typedef nrf_atomic_u32_t nrf_mtx_t
 Mutex data type. More...


__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.

[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.

[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.

[in,out]p_mtxThe mutex to be locked.
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.

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

Documentation feedback | Developer Zone | Subscribe | Updated