diff options
| author | wusongjie <[email protected]> | 2023-07-05 13:38:29 +0800 |
|---|---|---|
| committer | wusongjie <[email protected]> | 2023-07-05 13:38:29 +0800 |
| commit | 3b7e46de7eae5ed96e24cdfca0d5866a71cb6dd6 (patch) | |
| tree | 55fed6861acb92ad5a9ae6e5d2ef7ef7f90d094a /include/rtatomic.h | |
| parent | 179157f4e198ded6ca92841226b7b4317a180b9a (diff) | |
AArch64: support hardware atomic
Support aarch64 rt_hw_atomic_* api.
Add atomic implemente by rt_atomic api:
rt_atomic_dec_and_test
rt_atomic_fetch_add_unless
rt_atomic_add_unless
rt_atomic_inc_not_zero
Signed-off-by: GuEe-GUI <[email protected]>
Diffstat (limited to 'include/rtatomic.h')
| -rw-r--r-- | include/rtatomic.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/include/rtatomic.h b/include/rtatomic.h index d711a64a05..9f361fd925 100644 --- a/include/rtatomic.h +++ b/include/rtatomic.h @@ -11,6 +11,8 @@ #ifndef __RT_ATOMIC_H__ #define __RT_ATOMIC_H__ +#include <rthw.h> + #if !defined(__cplusplus) rt_atomic_t rt_hw_atomic_load(volatile rt_atomic_t *ptr); @@ -206,6 +208,35 @@ rt_inline rt_atomic_t rt_soft_atomic_compare_exchange_strong(volatile rt_atomic_ } #endif /* RT_USING_STDC_ATOMIC */ +rt_inline rt_bool_t rt_atomic_dec_and_test(volatile rt_atomic_t *ptr) +{ + return rt_atomic_sub(ptr, 1) == 0; +} + +rt_inline rt_atomic_t rt_atomic_fetch_add_unless(volatile rt_atomic_t *ptr, rt_atomic_t a, rt_atomic_t u) +{ + rt_atomic_t c = rt_atomic_load(ptr); + + do { + if (c == u) + { + break; + } + } while (!rt_atomic_compare_exchange_strong(ptr, &c, c + a)); + + return c; +} + +rt_inline rt_bool_t rt_atomic_add_unless(volatile rt_atomic_t *ptr, rt_atomic_t a, rt_atomic_t u) +{ + return rt_atomic_fetch_add_unless(ptr, a, u) != u; +} + +rt_inline rt_bool_t rt_atomic_inc_not_zero(volatile rt_atomic_t *ptr) +{ + return rt_atomic_add_unless(ptr, 1, 0); +} + #endif /* __cplusplus */ #endif /* __RT_ATOMIC_H__ */ |
