16 #ifndef _RTEMS_SCORE_CPUSTDATOMIC_H 17 #define _RTEMS_SCORE_CPUSTDATOMIC_H 32 #if defined(__cplusplus) \ 33 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)) 43 #define _RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC 45 #include <stdatomic.h> 46 #define _RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC 52 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 54 typedef std::atomic_uint CPU_atomic_Uint;
56 typedef std::atomic_ulong CPU_atomic_Ulong;
58 typedef std::atomic_uintptr_t CPU_atomic_Uintptr;
60 typedef std::atomic_flag CPU_atomic_Flag;
62 typedef std::memory_order CPU_atomic_Order;
64 #define CPU_ATOMIC_ORDER_RELAXED std::memory_order_relaxed 66 #define CPU_ATOMIC_ORDER_ACQUIRE std::memory_order_acquire 68 #define CPU_ATOMIC_ORDER_RELEASE std::memory_order_release 70 #define CPU_ATOMIC_ORDER_ACQ_REL std::memory_order_acq_rel 72 #define CPU_ATOMIC_ORDER_SEQ_CST std::memory_order_seq_cst 74 #define CPU_ATOMIC_INITIALIZER_UINT( value ) ATOMIC_VAR_INIT( value ) 76 #define CPU_ATOMIC_INITIALIZER_ULONG( value ) ATOMIC_VAR_INIT( value ) 78 #define CPU_ATOMIC_INITIALIZER_UINTPTR( value ) ATOMIC_VAR_INIT( value ) 80 #define CPU_ATOMIC_INITIALIZER_FLAG ATOMIC_FLAG_INIT 82 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 84 typedef atomic_uint CPU_atomic_Uint;
86 typedef atomic_ulong CPU_atomic_Ulong;
88 typedef atomic_uintptr_t CPU_atomic_Uintptr;
90 typedef atomic_flag CPU_atomic_Flag;
92 typedef memory_order CPU_atomic_Order;
94 #define CPU_ATOMIC_ORDER_RELAXED memory_order_relaxed 96 #define CPU_ATOMIC_ORDER_ACQUIRE memory_order_acquire 98 #define CPU_ATOMIC_ORDER_RELEASE memory_order_release 100 #define CPU_ATOMIC_ORDER_ACQ_REL memory_order_acq_rel 102 #define CPU_ATOMIC_ORDER_SEQ_CST memory_order_seq_cst 104 #define CPU_ATOMIC_INITIALIZER_UINT( value ) ATOMIC_VAR_INIT( value ) 106 #define CPU_ATOMIC_INITIALIZER_ULONG( value ) ATOMIC_VAR_INIT( value ) 108 #define CPU_ATOMIC_INITIALIZER_UINTPTR( value ) ATOMIC_VAR_INIT( value ) 110 #define CPU_ATOMIC_INITIALIZER_FLAG ATOMIC_FLAG_INIT 114 typedef unsigned int CPU_atomic_Uint;
116 typedef unsigned long CPU_atomic_Ulong;
118 typedef uintptr_t CPU_atomic_Uintptr;
120 typedef bool CPU_atomic_Flag;
122 typedef int CPU_atomic_Order;
124 #define CPU_ATOMIC_ORDER_RELAXED 0 126 #define CPU_ATOMIC_ORDER_ACQUIRE 2 128 #define CPU_ATOMIC_ORDER_RELEASE 3 130 #define CPU_ATOMIC_ORDER_ACQ_REL 4 132 #define CPU_ATOMIC_ORDER_SEQ_CST 5 134 #define CPU_ATOMIC_INITIALIZER_UINT( value ) ( value ) 136 #define CPU_ATOMIC_INITIALIZER_ULONG( value ) ( value ) 138 #define CPU_ATOMIC_INITIALIZER_UINTPTR( value ) ( value ) 140 #define CPU_ATOMIC_INITIALIZER_FLAG false 149 static inline void _CPU_atomic_Fence( CPU_atomic_Order order )
151 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 152 std::atomic_thread_fence( order );
153 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 154 atomic_thread_fence( order );
167 static inline void _CPU_atomic_Init_uint( CPU_atomic_Uint *obj,
unsigned int desired )
169 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 170 obj->store( desired );
171 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 172 atomic_init( obj, desired );
184 static inline void _CPU_atomic_Init_ulong( CPU_atomic_Ulong *obj,
unsigned long desired )
186 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 187 obj->store( desired );
188 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 189 atomic_init( obj, desired );
201 static inline void _CPU_atomic_Init_uintptr( CPU_atomic_Uintptr *obj, uintptr_t desired )
203 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 204 obj->store( desired );
205 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 206 atomic_init( obj, desired );
220 static inline unsigned int _CPU_atomic_Load_uint(
const CPU_atomic_Uint *obj, CPU_atomic_Order order )
222 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 223 return obj->load( order );
224 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 225 return atomic_load_explicit( obj, order );
245 static inline unsigned long _CPU_atomic_Load_ulong(
const CPU_atomic_Ulong *obj, CPU_atomic_Order order )
247 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 248 return obj->load( order );
249 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 250 return atomic_load_explicit( obj, order );
270 static inline uintptr_t _CPU_atomic_Load_uintptr(
const CPU_atomic_Uintptr *obj, CPU_atomic_Order order )
272 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 273 return obj->load( order );
274 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 275 return atomic_load_explicit( obj, order );
294 static inline void _CPU_atomic_Store_uint( CPU_atomic_Uint *obj,
unsigned int desired, CPU_atomic_Order order )
296 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 297 obj->store( desired );
298 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 299 atomic_store_explicit( obj, desired, order );
314 static inline void _CPU_atomic_Store_ulong( CPU_atomic_Ulong *obj,
unsigned long desired, CPU_atomic_Order order )
316 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 317 obj->store( desired );
318 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 319 atomic_store_explicit( obj, desired, order );
334 static inline void _CPU_atomic_Store_uintptr( CPU_atomic_Uintptr *obj, uintptr_t desired, CPU_atomic_Order order )
336 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 337 obj->store( desired );
338 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 339 atomic_store_explicit( obj, desired, order );
356 static inline unsigned int _CPU_atomic_Fetch_add_uint( CPU_atomic_Uint *obj,
unsigned int arg, CPU_atomic_Order order )
358 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 359 return obj->fetch_add( arg, order );
360 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 361 return atomic_fetch_add_explicit( obj, arg, order );
385 static inline unsigned long _CPU_atomic_Fetch_add_ulong( CPU_atomic_Ulong *obj,
unsigned long arg, CPU_atomic_Order order )
387 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 388 return obj->fetch_add( arg, order );
389 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 390 return atomic_fetch_add_explicit( obj, arg, order );
414 static inline uintptr_t _CPU_atomic_Fetch_add_uintptr( CPU_atomic_Uintptr *obj, uintptr_t arg, CPU_atomic_Order order )
416 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 417 return obj->fetch_add( arg, order );
418 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 419 return atomic_fetch_add_explicit( obj, arg, order );
443 static inline unsigned int _CPU_atomic_Fetch_sub_uint( CPU_atomic_Uint *obj,
unsigned int arg, CPU_atomic_Order order )
445 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 446 return obj->fetch_sub( arg, order );
447 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 448 return atomic_fetch_sub_explicit( obj, arg, order );
472 static inline unsigned long _CPU_atomic_Fetch_sub_ulong( CPU_atomic_Ulong *obj,
unsigned long arg, CPU_atomic_Order order )
474 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 475 return obj->fetch_sub( arg, order );
476 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 477 return atomic_fetch_sub_explicit( obj, arg, order );
501 static inline uintptr_t _CPU_atomic_Fetch_sub_uintptr( CPU_atomic_Uintptr *obj, uintptr_t arg, CPU_atomic_Order order )
503 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 504 return obj->fetch_sub( arg, order );
505 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 506 return atomic_fetch_sub_explicit( obj, arg, order );
530 static inline unsigned int _CPU_atomic_Fetch_or_uint( CPU_atomic_Uint *obj,
unsigned int arg, CPU_atomic_Order order )
532 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 533 return obj->fetch_or( arg, order );
534 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 535 return atomic_fetch_or_explicit( obj, arg, order );
559 static inline unsigned long _CPU_atomic_Fetch_or_ulong( CPU_atomic_Ulong *obj,
unsigned long arg, CPU_atomic_Order order )
561 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 562 return obj->fetch_or( arg, order );
563 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 564 return atomic_fetch_or_explicit( obj, arg, order );
588 static inline uintptr_t _CPU_atomic_Fetch_or_uintptr( CPU_atomic_Uintptr *obj, uintptr_t arg, CPU_atomic_Order order )
590 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 591 return obj->fetch_or( arg, order );
592 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 593 return atomic_fetch_or_explicit( obj, arg, order );
617 static inline unsigned int _CPU_atomic_Fetch_and_uint( CPU_atomic_Uint *obj,
unsigned int arg, CPU_atomic_Order order )
619 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 620 return obj->fetch_and( arg, order );
621 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 622 return atomic_fetch_and_explicit( obj, arg, order );
646 static inline unsigned long _CPU_atomic_Fetch_and_ulong( CPU_atomic_Ulong *obj,
unsigned long arg, CPU_atomic_Order order )
648 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 649 return obj->fetch_and( arg, order );
650 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 651 return atomic_fetch_and_explicit( obj, arg, order );
675 static inline uintptr_t _CPU_atomic_Fetch_and_uintptr( CPU_atomic_Uintptr *obj, uintptr_t arg, CPU_atomic_Order order )
677 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 678 return obj->fetch_and( arg, order );
679 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 680 return atomic_fetch_and_explicit( obj, arg, order );
704 static inline unsigned int _CPU_atomic_Exchange_uint( CPU_atomic_Uint *obj,
unsigned int desired, CPU_atomic_Order order )
706 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 707 return obj->exchange( desired, order );
708 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 709 return atomic_exchange_explicit( obj, desired, order );
733 static inline unsigned long _CPU_atomic_Exchange_ulong( CPU_atomic_Ulong *obj,
unsigned long desired, CPU_atomic_Order order )
735 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 736 return obj->exchange( desired, order );
737 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 738 return atomic_exchange_explicit( obj, desired, order );
762 static inline uintptr_t _CPU_atomic_Exchange_uintptr( CPU_atomic_Uintptr *obj, uintptr_t desired, CPU_atomic_Order order )
764 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 765 return obj->exchange( desired, order );
766 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 767 return atomic_exchange_explicit( obj, desired, order );
799 static inline bool _CPU_atomic_Compare_exchange_uint( CPU_atomic_Uint *obj,
unsigned int *expected,
unsigned int desired, CPU_atomic_Order succ, CPU_atomic_Order fail )
801 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 802 return obj->compare_exchange_strong( *expected, desired, succ, fail );
803 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 804 return atomic_compare_exchange_strong_explicit( obj, expected, desired, succ, fail );
814 success = ( actual == *expected );
843 static inline bool _CPU_atomic_Compare_exchange_ulong( CPU_atomic_Ulong *obj,
unsigned long *expected,
unsigned long desired, CPU_atomic_Order succ, CPU_atomic_Order fail )
845 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 846 return obj->compare_exchange_strong( *expected, desired, succ, fail );
847 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 848 return atomic_compare_exchange_strong_explicit( obj, expected, desired, succ, fail );
852 unsigned long actual;
858 success = ( actual == *expected );
887 static inline bool _CPU_atomic_Compare_exchange_uintptr( CPU_atomic_Uintptr *obj, uintptr_t *expected, uintptr_t desired, CPU_atomic_Order succ, CPU_atomic_Order fail )
889 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 890 return obj->compare_exchange_strong( *expected, desired, succ, fail );
891 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 892 return atomic_compare_exchange_strong_explicit( obj, expected, desired, succ, fail );
902 success = ( actual == *expected );
920 static inline void _CPU_atomic_Flag_clear( CPU_atomic_Flag *obj, CPU_atomic_Order order )
922 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 924 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 925 atomic_flag_clear_explicit( obj, order );
941 static inline bool _CPU_atomic_Flag_test_and_set( CPU_atomic_Flag *obj, CPU_atomic_Order order )
943 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 944 return obj->test_and_set( order );
945 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 946 return atomic_flag_test_and_set_explicit( obj, order );
#define _ISR_Local_disable(_level)
Disables interrupts on this processor.
Definition: isrlevel.h:57
#define RTEMS_COMPILER_MEMORY_BARRIER()
Definition: basedefs.h:77
uint32_t ISR_Level
Definition: isrlevel.h:41
#define _ISR_Local_enable(_level)
Enables interrupts on this processor.
Definition: isrlevel.h:74