123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #ifndef NRF_MTX_H__
- #define NRF_MTX_H__
- #include <stdint.h>
- #include <stdbool.h>
- #include "nrf.h"
- #include "nrf_atomic.h"
- #include "nrf_assert.h"
- #define NRF_MTX_LOCKED 1
- #define NRF_MTX_UNLOCKED 0
- typedef nrf_atomic_u32_t nrf_mtx_t;
- __STATIC_INLINE void nrf_mtx_init(nrf_mtx_t * p_mtx);
- __STATIC_INLINE void nrf_mtx_destroy(nrf_mtx_t * p_mtx);
- __STATIC_INLINE bool nrf_mtx_trylock(nrf_mtx_t * p_mtx);
- __STATIC_INLINE void nrf_mtx_unlock(nrf_mtx_t * p_mtx);
- #ifndef SUPPRESS_INLINE_IMPLEMENTATION
- __STATIC_INLINE void nrf_mtx_init(nrf_mtx_t * p_mtx)
- {
- ASSERT(p_mtx != NULL);
- *p_mtx = NRF_MTX_UNLOCKED;
- __DMB();
- }
- __STATIC_INLINE void nrf_mtx_destroy(nrf_mtx_t * p_mtx)
- {
- ASSERT(p_mtx != NULL);
-
-
- __DMB();
- *p_mtx = NRF_MTX_UNLOCKED;
- }
- __STATIC_INLINE bool nrf_mtx_trylock(nrf_mtx_t * p_mtx)
- {
- ASSERT(p_mtx != NULL);
- uint32_t old_val = nrf_atomic_u32_fetch_store(p_mtx, NRF_MTX_LOCKED);
-
-
- __DMB();
- return (old_val == NRF_MTX_UNLOCKED);
- }
- __STATIC_INLINE void nrf_mtx_unlock(nrf_mtx_t * p_mtx)
- {
- ASSERT(p_mtx != NULL);
- ASSERT(*p_mtx == NRF_MTX_LOCKED);
-
-
- __DMB();
- *p_mtx = NRF_MTX_UNLOCKED;
- }
- #endif
- #endif
|