11#ifndef __RT_ATOMIC_H__
12#define __RT_ATOMIC_H__
16#if !defined(__cplusplus)
30#if defined(RT_USING_STDC_ATOMIC)
32#ifndef __STDC_NO_ATOMICS__
33#define rt_atomic_load(ptr) atomic_load(ptr)
34#define rt_atomic_store(ptr, v) atomic_store(ptr, v)
35#define rt_atomic_add(ptr, v) atomic_fetch_add(ptr, v)
36#define rt_atomic_sub(ptr, v) atomic_fetch_sub(ptr, v)
37#define rt_atomic_and(ptr, v) atomic_fetch_and(ptr, v)
38#define rt_atomic_or(ptr, v) atomic_fetch_or(ptr, v)
39#define rt_atomic_xor(ptr, v) atomic_fetch_xor(ptr, v)
40#define rt_atomic_exchange(ptr, v) atomic_exchange(ptr, v)
41#define rt_atomic_flag_clear(ptr) atomic_flag_clear(ptr)
42#define rt_atomic_flag_test_and_set(ptr) atomic_flag_test_and_set(ptr)
43#define rt_atomic_compare_exchange_strong(ptr, v,des) atomic_compare_exchange_strong(ptr, v ,des)
45#error "The standard library C doesn't support the atomic operation"
48#elif defined(RT_USING_HW_ATOMIC)
49#define rt_atomic_load(ptr) rt_hw_atomic_load(ptr)
50#define rt_atomic_store(ptr, v) rt_hw_atomic_store(ptr, v)
51#define rt_atomic_add(ptr, v) rt_hw_atomic_add(ptr, v)
52#define rt_atomic_sub(ptr, v) rt_hw_atomic_sub(ptr, v)
53#define rt_atomic_and(ptr, v) rt_hw_atomic_and(ptr, v)
54#define rt_atomic_or(ptr, v) rt_hw_atomic_or(ptr, v)
55#define rt_atomic_xor(ptr, v) rt_hw_atomic_xor(ptr, v)
56#define rt_atomic_exchange(ptr, v) rt_hw_atomic_exchange(ptr, v)
57#define rt_atomic_flag_clear(ptr) rt_hw_atomic_flag_clear(ptr)
58#define rt_atomic_flag_test_and_set(ptr) rt_hw_atomic_flag_test_and_set(ptr)
59#define rt_atomic_compare_exchange_strong(ptr, v,des) rt_hw_atomic_compare_exchange_strong(ptr, v ,des)
63#define rt_atomic_load(ptr) rt_soft_atomic_load(ptr)
64#define rt_atomic_store(ptr, v) rt_soft_atomic_store(ptr, v)
65#define rt_atomic_add(ptr, v) rt_soft_atomic_add(ptr, v)
66#define rt_atomic_sub(ptr, v) rt_soft_atomic_sub(ptr, v)
67#define rt_atomic_and(ptr, v) rt_soft_atomic_and(ptr, v)
68#define rt_atomic_or(ptr, v) rt_soft_atomic_or(ptr, v)
69#define rt_atomic_xor(ptr, v) rt_soft_atomic_xor(ptr, v)
70#define rt_atomic_exchange(ptr, v) rt_soft_atomic_exchange(ptr, v)
71#define rt_atomic_flag_clear(ptr) rt_soft_atomic_flag_clear(ptr)
72#define rt_atomic_flag_test_and_set(ptr) rt_soft_atomic_flag_test_and_set(ptr)
73#define rt_atomic_compare_exchange_strong(ptr, v,des) rt_soft_atomic_compare_exchange_strong(ptr, v ,des)
189 if ((*ptr1) != (*ptr2))
void rt_hw_atomic_flag_clear(volatile rt_atomic_t *ptr)
rt_inline rt_bool_t rt_atomic_dec_and_test(volatile rt_atomic_t *ptr)
rt_inline rt_atomic_t rt_atomic_fetch_add_unless(volatile rt_atomic_t *ptr, rt_atomic_t a, rt_atomic_t u)
#define rt_atomic_sub(ptr, v)
rt_atomic_t rt_hw_atomic_exchange(volatile rt_atomic_t *ptr, rt_atomic_t val)
rt_atomic_t rt_hw_atomic_xor(volatile rt_atomic_t *ptr, rt_atomic_t val)
rt_inline void rt_ll_slist_init(rt_ll_slist_t *l)
initialize a lock-less single list
rt_inline rt_ll_slist_t * rt_ll_slist_dequeue(rt_ll_slist_t *l)
rt_inline rt_atomic_t rt_soft_atomic_and(volatile rt_atomic_t *ptr, rt_atomic_t val)
rt_atomic_t rt_hw_atomic_sub(volatile rt_atomic_t *ptr, rt_atomic_t val)
rt_inline rt_bool_t rt_atomic_inc_not_zero(volatile rt_atomic_t *ptr)
void rt_hw_atomic_store(volatile rt_atomic_t *ptr, rt_atomic_t val)
#define rt_atomic_compare_exchange_strong(ptr, v, des)
rt_atomic_t rt_hw_atomic_or(volatile rt_atomic_t *ptr, rt_atomic_t val)
rt_inline void rt_ll_slist_enqueue(rt_ll_slist_t *l, rt_ll_slist_t *n)
rt_inline rt_atomic_t rt_soft_atomic_load(volatile rt_atomic_t *ptr)
rt_inline rt_atomic_t rt_soft_atomic_sub(volatile rt_atomic_t *ptr, rt_atomic_t val)
rt_inline rt_atomic_t rt_soft_atomic_add(volatile rt_atomic_t *ptr, rt_atomic_t val)
rt_inline rt_bool_t rt_atomic_add_unless(volatile rt_atomic_t *ptr, rt_atomic_t a, rt_atomic_t u)
rt_inline rt_atomic_t rt_soft_atomic_xor(volatile rt_atomic_t *ptr, rt_atomic_t val)
rt_atomic_t rt_hw_atomic_and(volatile rt_atomic_t *ptr, rt_atomic_t val)
#define rt_atomic_load(ptr)
rt_atomic_t rt_hw_atomic_load(volatile rt_atomic_t *ptr)
rt_inline rt_atomic_t rt_soft_atomic_exchange(volatile rt_atomic_t *ptr, rt_atomic_t val)
rt_inline void rt_soft_atomic_flag_clear(volatile rt_atomic_t *ptr)
rt_atomic_t rt_hw_atomic_add(volatile rt_atomic_t *ptr, rt_atomic_t val)
rt_atomic_t rt_hw_atomic_compare_exchange_strong(volatile rt_atomic_t *ptr, rt_atomic_t *expected, rt_atomic_t desired)
rt_inline rt_atomic_t rt_soft_atomic_flag_test_and_set(volatile rt_atomic_t *ptr)
rt_inline void rt_soft_atomic_store(volatile rt_atomic_t *ptr, rt_atomic_t val)
rt_atomic_t rt_hw_atomic_flag_test_and_set(volatile rt_atomic_t *ptr)
rt_inline rt_atomic_t rt_soft_atomic_compare_exchange_strong(volatile rt_atomic_t *ptr1, rt_atomic_t *ptr2, rt_atomic_t desired)
rt_inline rt_atomic_t rt_soft_atomic_or(volatile rt_atomic_t *ptr, rt_atomic_t val)
void rt_hw_interrupt_enable(rt_base_t level)
rt_base_t rt_hw_interrupt_disable(void)
struct rt_lockless_slist_node rt_ll_slist_t