diff options
| author | guo <[email protected]> | 2023-07-06 16:52:30 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-07-06 16:52:30 +0800 |
| commit | 78867912c114966d49e003db2ffb3407a5017b46 (patch) | |
| tree | e8b34c99bbf57feb4e1e976993d01ef6f9d3fd13 /include/rtatomic.h | |
| parent | c7be260665c9c753b343141968755d47deadd753 (diff) | |
| parent | fa10a99c3ccecd6113d30842a05e1b853cf7d1cb (diff) | |
Merge pull request #7788 from ErikChanHub/master
【dd2.0】Support Open Firmware API
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__ */ |
