16 #ifndef _RTEMS_SCORE_CPUSTDATOMIC_H 17 #define _RTEMS_SCORE_CPUSTDATOMIC_H 22 #if defined(__cplusplus) \ 23 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)) 33 #define _RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC 35 #include <stdatomic.h> 36 #define _RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC 42 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 44 typedef std::atomic_uint CPU_atomic_Uint;
46 typedef std::atomic_ulong CPU_atomic_Ulong;
48 typedef std::atomic_uintptr_t CPU_atomic_Uintptr;
50 typedef std::atomic_flag CPU_atomic_Flag;
52 typedef std::memory_order CPU_atomic_Order;
54 #define CPU_ATOMIC_ORDER_RELAXED std::memory_order_relaxed 56 #define CPU_ATOMIC_ORDER_ACQUIRE std::memory_order_acquire 58 #define CPU_ATOMIC_ORDER_RELEASE std::memory_order_release 60 #define CPU_ATOMIC_ORDER_ACQ_REL std::memory_order_acq_rel 62 #define CPU_ATOMIC_ORDER_SEQ_CST std::memory_order_seq_cst 64 #define CPU_ATOMIC_INITIALIZER_UINT( value ) ATOMIC_VAR_INIT( value ) 66 #define CPU_ATOMIC_INITIALIZER_ULONG( value ) ATOMIC_VAR_INIT( value ) 68 #define CPU_ATOMIC_INITIALIZER_UINTPTR( value ) ATOMIC_VAR_INIT( value ) 70 #define CPU_ATOMIC_INITIALIZER_FLAG ATOMIC_FLAG_INIT 72 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 74 typedef atomic_uint CPU_atomic_Uint;
76 typedef atomic_ulong CPU_atomic_Ulong;
78 typedef atomic_uintptr_t CPU_atomic_Uintptr;
80 typedef atomic_flag CPU_atomic_Flag;
82 typedef memory_order CPU_atomic_Order;
84 #define CPU_ATOMIC_ORDER_RELAXED memory_order_relaxed 86 #define CPU_ATOMIC_ORDER_ACQUIRE memory_order_acquire 88 #define CPU_ATOMIC_ORDER_RELEASE memory_order_release 90 #define CPU_ATOMIC_ORDER_ACQ_REL memory_order_acq_rel 92 #define CPU_ATOMIC_ORDER_SEQ_CST memory_order_seq_cst 94 #define CPU_ATOMIC_INITIALIZER_UINT( value ) ATOMIC_VAR_INIT( value ) 96 #define CPU_ATOMIC_INITIALIZER_ULONG( value ) ATOMIC_VAR_INIT( value ) 98 #define CPU_ATOMIC_INITIALIZER_UINTPTR( value ) ATOMIC_VAR_INIT( value ) 100 #define CPU_ATOMIC_INITIALIZER_FLAG ATOMIC_FLAG_INIT 104 typedef unsigned int CPU_atomic_Uint;
106 typedef unsigned long CPU_atomic_Ulong;
108 typedef uintptr_t CPU_atomic_Uintptr;
110 typedef bool CPU_atomic_Flag;
112 typedef int CPU_atomic_Order;
114 #define CPU_ATOMIC_ORDER_RELAXED 0 116 #define CPU_ATOMIC_ORDER_ACQUIRE 2 118 #define CPU_ATOMIC_ORDER_RELEASE 3 120 #define CPU_ATOMIC_ORDER_ACQ_REL 4 122 #define CPU_ATOMIC_ORDER_SEQ_CST 5 124 #define CPU_ATOMIC_INITIALIZER_UINT( value ) ( value ) 126 #define CPU_ATOMIC_INITIALIZER_ULONG( value ) ( value ) 128 #define CPU_ATOMIC_INITIALIZER_UINTPTR( value ) ( value ) 130 #define CPU_ATOMIC_INITIALIZER_FLAG false 134 static inline void _CPU_atomic_Fence( CPU_atomic_Order order )
136 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 137 std::atomic_thread_fence( order );
138 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 139 atomic_thread_fence( order );
146 static inline void _CPU_atomic_Init_uint( CPU_atomic_Uint *obj,
unsigned int desired )
148 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 149 obj->store( desired );
150 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 151 atomic_init( obj, desired );
157 static inline void _CPU_atomic_Init_ulong( CPU_atomic_Ulong *obj,
unsigned long desired )
159 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 160 obj->store( desired );
161 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 162 atomic_init( obj, desired );
168 static inline void _CPU_atomic_Init_uintptr( CPU_atomic_Uintptr *obj, uintptr_t desired )
170 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 171 obj->store( desired );
172 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 173 atomic_init( obj, desired );
179 static inline unsigned int _CPU_atomic_Load_uint(
const CPU_atomic_Uint *obj, CPU_atomic_Order order )
181 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 182 return obj->load( order );
183 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 184 return atomic_load_explicit( obj, order );
196 static inline unsigned long _CPU_atomic_Load_ulong(
const CPU_atomic_Ulong *obj, CPU_atomic_Order order )
198 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 199 return obj->load( order );
200 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 201 return atomic_load_explicit( obj, order );
213 static inline uintptr_t _CPU_atomic_Load_uintptr(
const CPU_atomic_Uintptr *obj, CPU_atomic_Order order )
215 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 216 return obj->load( order );
217 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 218 return atomic_load_explicit( obj, order );
230 static inline void _CPU_atomic_Store_uint( CPU_atomic_Uint *obj,
unsigned int desired, CPU_atomic_Order order )
232 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 233 obj->store( desired );
234 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 235 atomic_store_explicit( obj, desired, order );
243 static inline void _CPU_atomic_Store_ulong( CPU_atomic_Ulong *obj,
unsigned long desired, CPU_atomic_Order order )
245 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 246 obj->store( desired );
247 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 248 atomic_store_explicit( obj, desired, order );
256 static inline void _CPU_atomic_Store_uintptr( CPU_atomic_Uintptr *obj, uintptr_t desired, CPU_atomic_Order order )
258 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 259 obj->store( desired );
260 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 261 atomic_store_explicit( obj, desired, order );
269 static inline unsigned int _CPU_atomic_Fetch_add_uint( CPU_atomic_Uint *obj,
unsigned int arg, CPU_atomic_Order order )
271 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 272 return obj->fetch_add( arg, order );
273 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 274 return atomic_fetch_add_explicit( obj, arg, order );
289 static inline unsigned long _CPU_atomic_Fetch_add_ulong( CPU_atomic_Ulong *obj,
unsigned long arg, CPU_atomic_Order order )
291 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 292 return obj->fetch_add( arg, order );
293 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 294 return atomic_fetch_add_explicit( obj, arg, order );
309 static inline uintptr_t _CPU_atomic_Fetch_add_uintptr( CPU_atomic_Uintptr *obj, uintptr_t arg, CPU_atomic_Order order )
311 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 312 return obj->fetch_add( arg, order );
313 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 314 return atomic_fetch_add_explicit( obj, arg, order );
329 static inline unsigned int _CPU_atomic_Fetch_sub_uint( CPU_atomic_Uint *obj,
unsigned int arg, CPU_atomic_Order order )
331 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 332 return obj->fetch_sub( arg, order );
333 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 334 return atomic_fetch_sub_explicit( obj, arg, order );
349 static inline unsigned long _CPU_atomic_Fetch_sub_ulong( CPU_atomic_Ulong *obj,
unsigned long arg, CPU_atomic_Order order )
351 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 352 return obj->fetch_sub( arg, order );
353 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 354 return atomic_fetch_sub_explicit( obj, arg, order );
369 static inline uintptr_t _CPU_atomic_Fetch_sub_uintptr( CPU_atomic_Uintptr *obj, uintptr_t arg, CPU_atomic_Order order )
371 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 372 return obj->fetch_sub( arg, order );
373 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 374 return atomic_fetch_sub_explicit( obj, arg, order );
389 static inline unsigned int _CPU_atomic_Fetch_or_uint( CPU_atomic_Uint *obj,
unsigned int arg, CPU_atomic_Order order )
391 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 392 return obj->fetch_or( arg, order );
393 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 394 return atomic_fetch_or_explicit( obj, arg, order );
409 static inline unsigned long _CPU_atomic_Fetch_or_ulong( CPU_atomic_Ulong *obj,
unsigned long arg, CPU_atomic_Order order )
411 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 412 return obj->fetch_or( arg, order );
413 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 414 return atomic_fetch_or_explicit( obj, arg, order );
429 static inline uintptr_t _CPU_atomic_Fetch_or_uintptr( CPU_atomic_Uintptr *obj, uintptr_t arg, CPU_atomic_Order order )
431 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 432 return obj->fetch_or( arg, order );
433 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 434 return atomic_fetch_or_explicit( obj, arg, order );
449 static inline unsigned int _CPU_atomic_Fetch_and_uint( CPU_atomic_Uint *obj,
unsigned int arg, CPU_atomic_Order order )
451 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 452 return obj->fetch_and( arg, order );
453 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 454 return atomic_fetch_and_explicit( obj, arg, order );
469 static inline unsigned long _CPU_atomic_Fetch_and_ulong( CPU_atomic_Ulong *obj,
unsigned long arg, CPU_atomic_Order order )
471 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 472 return obj->fetch_and( arg, order );
473 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 474 return atomic_fetch_and_explicit( obj, arg, order );
489 static inline uintptr_t _CPU_atomic_Fetch_and_uintptr( CPU_atomic_Uintptr *obj, uintptr_t arg, CPU_atomic_Order order )
491 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 492 return obj->fetch_and( arg, order );
493 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 494 return atomic_fetch_and_explicit( obj, arg, order );
509 static inline unsigned int _CPU_atomic_Exchange_uint( CPU_atomic_Uint *obj,
unsigned int desired, CPU_atomic_Order order )
511 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 512 return obj->exchange( desired, order );
513 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 514 return atomic_exchange_explicit( obj, desired, order );
529 static inline unsigned long _CPU_atomic_Exchange_ulong( CPU_atomic_Ulong *obj,
unsigned long desired, CPU_atomic_Order order )
531 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 532 return obj->exchange( desired, order );
533 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 534 return atomic_exchange_explicit( obj, desired, order );
549 static inline uintptr_t _CPU_atomic_Exchange_uintptr( CPU_atomic_Uintptr *obj, uintptr_t desired, CPU_atomic_Order order )
551 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 552 return obj->exchange( desired, order );
553 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 554 return atomic_exchange_explicit( obj, desired, order );
569 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 )
571 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 572 return obj->compare_exchange_strong( *expected, desired, succ, fail );
573 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 574 return atomic_compare_exchange_strong_explicit( obj, expected, desired, succ, fail );
584 success = ( actual == *expected );
596 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 )
598 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 599 return obj->compare_exchange_strong( *expected, desired, succ, fail );
600 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 601 return atomic_compare_exchange_strong_explicit( obj, expected, desired, succ, fail );
605 unsigned long actual;
611 success = ( actual == *expected );
623 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 )
625 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 626 return obj->compare_exchange_strong( *expected, desired, succ, fail );
627 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 628 return atomic_compare_exchange_strong_explicit( obj, expected, desired, succ, fail );
638 success = ( actual == *expected );
650 static inline void _CPU_atomic_Flag_clear( CPU_atomic_Flag *obj, CPU_atomic_Order order )
652 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 654 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 655 atomic_flag_clear_explicit( obj, order );
662 static inline bool _CPU_atomic_Flag_test_and_set( CPU_atomic_Flag *obj, CPU_atomic_Order order )
664 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC) 665 return obj->test_and_set( order );
666 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC) 667 return atomic_flag_test_and_set_explicit( obj, order );
#define _ISR_Local_disable(_level)
Disables interrupts on this processor.
Definition: isrlevel.h:54
uint32_t ISR_Level
Definition: isrlevel.h:38
#define _ISR_Local_enable(_level)
Enables interrupts on this processor.
Definition: isrlevel.h:71
#define RTEMS_COMPILER_MEMORY_BARRIER()
Definition: basedefs.h:76