Ignore:
Timestamp:
05/07/14 12:55:37 (9 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
dd510a0
Parents:
b42e148
git-author:
Sebastian Huber <sebastian.huber@…> (05/07/14 12:55:37)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/30/14 07:56:23)
Message:

score: Workaround for GCC 4.9 for atomic ops

The GCC 4.9 ships its own <stdatomic.h> which is not C++ compatible.
The suggested solution was to include <atomic> in case C++ is used.
This works at least with GCC 4.9. See also:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60932
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60940

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/include/rtems/score/atomic.h

    rb42e148 r89f8eab5  
    11/**
    2  * @file  rtems/score/atomic.h
    3  *
    4  * This include file defines the interface for all the atomic
    5  * operations which can be used in the synchronization primitives
    6  * or in the lock-less algorithms. You should not use these API
    7  * in the other components directly.
     2 * @file
     3 *
     4 * @ingroup ScoreAtomic
     5 *
     6 * @brief Atomic Operations API
    87 */
    98
     
    2120#include <rtems/score/cpuatomic.h>
    2221
    23 #ifdef __cplusplus
    24 extern "C" {
    25 #endif
    26 
    2722/**
    28  * @defgroup RTEMS atomic interface
     23 * @defgroup ScoreAtomic Atomic Operations
    2924 *
     25 * @ingroup Score
     26 *
     27 * @brief Support for atomic operations.
     28 *
     29 * Atomic operations can be used to implement low-level synchronization
     30 * primitives on SMP systems, like spin locks.  All atomic operations are
     31 * defined in terms of C11 (ISO/IEC 9899:2011) or C++11 (ISO/IEC 14882:2011).
     32 * For documentation use the standard documents.
     33 *
     34 * @{
    3035 */
    3136
    32 /**@{*/
     37typedef CPU_atomic_Uint Atomic_Uint;
    3338
    34 /**
    35  * @brief atomic data initializer for static initialization.
    36  */
    37 #define ATOMIC_INITIALIZER_UINT(value) CPU_ATOMIC_INITIALIZER_UINT(value)
    38 #define ATOMIC_INITIALIZER_ULONG(value) CPU_ATOMIC_INITIALIZER_ULONG(value)
    39 #define ATOMIC_INITIALIZER_PTR(value) CPU_ATOMIC_INITIALIZER_PTR(value)
     39typedef CPU_atomic_Ulong Atomic_Ulong;
    4040
    41 /**
    42  * @brief Initializes an atomic flag object to the cleared state.
    43  */
     41typedef CPU_atomic_Pointer Atomic_Pointer;
     42
     43typedef CPU_atomic_Flag Atomic_Flag;
     44
     45#define ATOMIC_ORDER_RELAXED CPU_ATOMIC_ORDER_RELAXED
     46
     47#define ATOMIC_ORDER_ACQUIRE CPU_ATOMIC_ORDER_ACQUIRE
     48
     49#define ATOMIC_ORDER_RELEASE CPU_ATOMIC_ORDER_RELEASE
     50
     51#define ATOMIC_ORDER_SEQ_CST CPU_ATOMIC_ORDER_SEQ_CST
     52
     53#define ATOMIC_INITIALIZER_UINT( value ) CPU_ATOMIC_INITIALIZER_UINT( value )
     54
     55#define ATOMIC_INITIALIZER_ULONG( value ) CPU_ATOMIC_INITIALIZER_ULONG( value )
     56
     57#define ATOMIC_INITIALIZER_PTR( value ) CPU_ATOMIC_INITIALIZER_PTR( value )
     58
    4459#define ATOMIC_INITIALIZER_FLAG CPU_ATOMIC_INITIALIZER_FLAG
    4560
    46 static inline void _Atomic_Fence(
    47   Atomic_Order order
    48 )
    49 {
    50   _CPU_atomic_Fence( order );
    51 }
     61#define _Atomic_Fence( order ) _CPU_atomic_Fence( order )
    5262
    53 /**
    54  * @brief Initializes an atomic type value into a atomic object.
    55  *
    56  * @param object an atomic type pointer of object.
    57  * @param pointer a pointer to be stored into object.
    58  */
    59 static inline void _Atomic_Init_uint(
    60   volatile Atomic_Uint *object,
    61   unsigned int value
    62 )
    63 {
    64   _CPU_atomic_Init_uint(object, value);
    65 }
     63#define _Atomic_Init_uint( obj, desired ) \
     64  _CPU_atomic_Init_uint( obj, desired )
    6665
    67 static inline void _Atomic_Init_ulong(
    68   volatile Atomic_Ulong *object,
    69   unsigned long value
    70 )
    71 {
    72   _CPU_atomic_Init_ulong(object, value);
    73 }
     66#define _Atomic_Init_ulong( obj, desired ) \
     67  _CPU_atomic_Init_ulong( obj, desired )
    7468
    75 static inline void _Atomic_Init_ptr(
    76   volatile Atomic_Pointer *object,
    77   void *pointer
    78 )
    79 {
    80   _CPU_atomic_Init_ptr(object, pointer);
    81 }
     69#define _Atomic_Init_ptr( obj, desired ) \
     70  _CPU_atomic_Init_ptr( obj, desired )
    8271
    83 /**
    84  * @brief Atomically load an atomic type value from atomic object.
    85  *
    86  * @param object an atomic type pointer of object.
    87  * @param order a type of Atomic_Order.
    88  *
    89  * The order shall not be ATOMIC_ORDER_RELEASE.
    90  */
    91 static inline unsigned int _Atomic_Load_uint(
    92   volatile Atomic_Uint *object,
    93   Atomic_Order order
    94 )
    95 {
    96   return _CPU_atomic_Load_uint( object, order );
    97 }
     72#define _Atomic_Load_uint( obj, order ) \
     73  _CPU_atomic_Load_uint( obj, order )
    9874
    99 static inline unsigned long _Atomic_Load_ulong(
    100   volatile Atomic_Ulong *object,
    101   Atomic_Order order
    102 )
    103 {
    104   return _CPU_atomic_Load_ulong( object, order );
    105 }
     75#define _Atomic_Load_ulong( obj, order ) \
     76  _CPU_atomic_Load_ulong( obj, order )
    10677
    107 static inline void *_Atomic_Load_ptr(
    108   volatile Atomic_Pointer *object,
    109   Atomic_Order order
    110 )
    111 {
    112   return _CPU_atomic_Load_ptr( object, order );
    113 }
     78#define _Atomic_Load_ptr( obj, order ) \
     79  _CPU_atomic_Load_ptr( obj, order )
    11480
    115 /**
    116  * @brief Atomically store an atomic type value into a atomic object.
    117  *
    118  * @param object an atomic type pointer of object.
    119  * @param value a value to be stored into object.
    120  * @param order a type of Atomic_Order.
    121  *
    122  * The order shall not be ATOMIC_ORDER_ACQUIRE.
    123  */
    124 static inline void _Atomic_Store_uint(
    125   volatile Atomic_Uint *object,
    126   unsigned int value,
    127   Atomic_Order order
    128 )
    129 {
    130   _CPU_atomic_Store_uint( object, value, order );
    131 }
     81#define _Atomic_Store_uint( obj, desr, order ) \
     82  _CPU_atomic_Store_uint( obj, desr, order )
    13283
    133 static inline void _Atomic_Store_ulong(
    134   volatile Atomic_Ulong *object,
    135   unsigned long value,
    136   Atomic_Order order
    137 )
    138 {
    139   _CPU_atomic_Store_ulong( object, value, order );
    140 }
     84#define _Atomic_Store_ulong( obj, desr, order ) \
     85  _CPU_atomic_Store_ulong( obj, desr, order )
    14186
    142 static inline void _Atomic_Store_ptr(
    143   volatile Atomic_Pointer *object,
    144   void *pointer,
    145   Atomic_Order order
    146 )
    147 {
    148   _CPU_atomic_Store_ptr( object, pointer, order );
    149 }
     87#define _Atomic_Store_ptr( obj, desr, order ) \
     88  _CPU_atomic_Store_ptr( obj, desr, order )
    15089
    151 /**
    152  * @brief Atomically load-add-store an atomic type value into object
    153  *
    154  * @param object a atomic type pointer of object.
    155  * @param value a value to be add and store into object.
    156  * @param order a type of Atomic_Order.
    157  *
    158  * @retval a result value before add ops.
    159  */
    160 static inline unsigned int _Atomic_Fetch_add_uint(
    161   volatile Atomic_Uint *object,
    162   unsigned int value,
    163   Atomic_Order order
    164 )
    165 {
    166   return _CPU_atomic_Fetch_add_uint( object, value, order );
    167 }
     90#define _Atomic_Fetch_add_uint( obj, arg, order ) \
     91  _CPU_atomic_Fetch_add_uint( obj, arg, order )
    16892
    169 static inline unsigned long _Atomic_Fetch_add_ulong(
    170   volatile Atomic_Ulong *object,
    171   unsigned long value,
    172   Atomic_Order order
    173 )
    174 {
    175   return _CPU_atomic_Fetch_add_ulong( object, value, order );
    176 }
     93#define _Atomic_Fetch_add_ulong( obj, arg, order ) \
     94  _CPU_atomic_Fetch_add_ulong( obj, arg, order )
    17795
    178 static inline uintptr_t _Atomic_Fetch_add_ptr(
    179   volatile Atomic_Pointer *object,
    180   uintptr_t value,
    181   Atomic_Order order
    182 )
    183 {
    184   return _CPU_atomic_Fetch_add_ptr( object, value, order );
    185 }
     96#define _Atomic_Fetch_add_ptr( obj, arg, order ) \
     97  _CPU_atomic_Fetch_add_ptr( obj, arg, order )
    18698
    187 /**
    188  * @brief Atomically load-sub-store an atomic type value into object
    189  *
    190  * @param object a atomic type pointer of object.
    191  * @param value a value to be sub and store into object.
    192  * @param order a type of Atomic_Order.
    193  *
    194  * @retval a result value before sub ops.
    195  */
    196 static inline unsigned int _Atomic_Fetch_sub_uint(
    197   volatile Atomic_Uint *object,
    198   unsigned int value,
    199   Atomic_Order order
    200 )
    201 {
    202   return _CPU_atomic_Fetch_sub_uint( object, value, order );
    203 }
     99#define _Atomic_Fetch_sub_uint( obj, arg, order ) \
     100  _CPU_atomic_Fetch_sub_uint( obj, arg, order )
    204101
    205 static inline unsigned long _Atomic_Fetch_sub_ulong(
    206   volatile Atomic_Ulong *object,
    207   unsigned long value,
    208   Atomic_Order order
    209 )
    210 {
    211   return _CPU_atomic_Fetch_sub_ulong( object, value, order );
    212 }
     102#define _Atomic_Fetch_sub_ulong( obj, arg, order ) \
     103  _CPU_atomic_Fetch_sub_ulong( obj, arg, order )
    213104
    214 static inline uintptr_t _Atomic_Fetch_sub_ptr(
    215   volatile Atomic_Pointer *object,
    216   uintptr_t value,
    217   Atomic_Order order
    218 )
    219 {
    220   return _CPU_atomic_Fetch_sub_ptr( object, value, order );
    221 }
     105#define _Atomic_Fetch_sub_ptr( obj, arg, order ) \
     106  _CPU_atomic_Fetch_sub_ptr( obj, arg, order )
    222107
    223 /**
    224  * @brief Atomically load-or-store an atomic type value into object
    225  *
    226  * @param object a atomic type pointer of object.
    227  * @param value a value to be or and store into object.
    228  * @param order a type of Atomic_Order.
    229  *
    230  * @retval a result value before or ops.
    231  */
    232 static inline unsigned int _Atomic_Fetch_or_uint(
    233   volatile Atomic_Uint *object,
    234   unsigned int value,
    235   Atomic_Order order
    236 )
    237 {
    238   return _CPU_atomic_Fetch_or_uint( object, value, order );
    239 }
     108#define _Atomic_Fetch_or_uint( obj, arg, order ) \
     109  _CPU_atomic_Fetch_or_uint( obj, arg, order )
    240110
    241 static inline unsigned long _Atomic_Fetch_or_ulong(
    242   volatile Atomic_Ulong *object,
    243   unsigned long value,
    244   Atomic_Order order
    245 )
    246 {
    247   return _CPU_atomic_Fetch_or_ulong( object, value, order );
    248 }
     111#define _Atomic_Fetch_or_ulong( obj, arg, order ) \
     112  _CPU_atomic_Fetch_or_ulong( obj, arg, order )
    249113
    250 static inline uintptr_t _Atomic_Fetch_or_ptr(
    251   volatile Atomic_Pointer *object,
    252   uintptr_t value,
    253   Atomic_Order order
    254 )
    255 {
    256   return _CPU_atomic_Fetch_or_ptr( object, value, order );
    257 }
     114#define _Atomic_Fetch_or_ptr( obj, arg, order ) \
     115  _CPU_atomic_Fetch_or_ptr( obj, arg, order )
    258116
    259 /**
    260  * @brief Atomically load-and-store an atomic type value into object
    261  *
    262  * @param object a atomic type pointer of object.
    263  * @param value a value to be and and store into object.
    264  * @param order a type of Atomic_Order.
    265  *
    266  * @retval a result value before and ops.
    267  */
    268 static inline unsigned int _Atomic_Fetch_and_uint(
    269   volatile Atomic_Uint *object,
    270   unsigned int value,
    271   Atomic_Order order
    272 )
    273 {
    274   return _CPU_atomic_Fetch_and_uint( object, value, order );
    275 }
     117#define _Atomic_Fetch_and_uint( obj, arg, order ) \
     118  _CPU_atomic_Fetch_and_uint( obj, arg, order )
    276119
    277 static inline unsigned long _Atomic_Fetch_and_ulong(
    278   volatile Atomic_Ulong *object,
    279   unsigned long value,
    280   Atomic_Order order
    281 )
    282 {
    283   return _CPU_atomic_Fetch_and_ulong( object, value, order );
    284 }
     120#define _Atomic_Fetch_and_ulong( obj, arg, order ) \
     121  _CPU_atomic_Fetch_and_ulong( obj, arg, order )
    285122
    286 static inline uintptr_t _Atomic_Fetch_and_ptr(
    287   volatile Atomic_Pointer *object,
    288   uintptr_t value,
    289   Atomic_Order order
    290 )
    291 {
    292   return _CPU_atomic_Fetch_and_ptr( object, value, order );
    293 }
     123#define _Atomic_Fetch_and_ptr( obj, arg, order ) \
     124  _CPU_atomic_Fetch_and_ptr( obj, arg, order )
    294125
    295 /**
    296  * @brief Atomically exchange an atomic type value into object
    297  *
    298  * @param object a atomic type pointer of object.
    299  * @param value a value to exchange and and store into object.
    300  * @param order a type of Atomic_Order.
    301  *
    302  * @retval a result value before exchange ops.
    303  */
    304 static inline unsigned int _Atomic_Exchange_uint(
    305  volatile Atomic_Uint *object,
    306  unsigned int value,
    307  Atomic_Order order
    308 )
    309 {
    310   return _CPU_atomic_Exchange_uint( object, value, order );
    311 }
     126#define _Atomic_Exchange_uint( obj, desr, order ) \
     127  _CPU_atomic_Exchange_uint( obj, desr, order )
    312128
    313 static inline unsigned long _Atomic_Exchange_ulong(
    314  volatile Atomic_Ulong *object,
    315  unsigned long value,
    316  Atomic_Order order
    317 )
    318 {
    319   return _CPU_atomic_Exchange_ulong( object, value, order );
    320 }
     129#define _Atomic_Exchange_ulong( obj, desr, order ) \
     130  _CPU_atomic_Exchange_ulong( obj, desr, order )
    321131
    322 static inline void *_Atomic_Exchange_ptr(
    323  volatile Atomic_Pointer *object,
    324  void *pointer,
    325  Atomic_Order order
    326 )
    327 {
    328   return _CPU_atomic_Exchange_ptr( object, pointer, order );
    329 }
     132#define _Atomic_Exchange_ptr( obj, desr, order ) \
     133  _CPU_atomic_Exchange_ptr( obj, desr, order )
    330134
    331 /**
    332  * @brief Atomically compare the value stored at object with a
    333  * old_value and if the two values are equal, update the value of a
    334  * address with a new_value
    335  *
    336  * @param object a atomic type pointer of object.
    337  * @param old_value pointer of a value.
    338  * @param new_value a atomic type value.
    339  * @param order_succ a type of Atomic_Order for successful exchange.
    340  * @param order_fail a type of Atomic_Order for failed exchange.
    341  *
    342  * @retval true if the compare exchange successully.
    343  * @retval false if the compare exchange failed.
    344  */
    345 static inline bool _Atomic_Compare_exchange_uint(
    346   volatile Atomic_Uint *object,
    347   unsigned int *old_value,
    348   unsigned int new_value,
    349   Atomic_Order order_succ,
    350   Atomic_Order order_fail
    351 )
    352 {
    353   return _CPU_atomic_Compare_exchange_uint( object, old_value, new_value,
    354     order_succ, order_fail );
    355 }
     135#define _Atomic_Compare_exchange_uint( obj, expected, desired, succ, fail ) \
     136  _CPU_atomic_Compare_exchange_uint( obj, expected, desired, succ, fail )
    356137
    357 static inline bool _Atomic_Compare_exchange_ulong(
    358   volatile Atomic_Ulong *object,
    359   unsigned long *old_value,
    360   unsigned long new_value,
    361   Atomic_Order order_succ,
    362   Atomic_Order order_fail
    363 )
    364 {
    365   return _CPU_atomic_Compare_exchange_ulong( object, old_value, new_value,
    366     order_succ, order_fail );
    367 }
     138#define _Atomic_Compare_exchange_ulong( obj, expected, desired, succ, fail ) \
     139  _CPU_atomic_Compare_exchange_ulong( obj, expected, desired, succ, fail )
    368140
    369 static inline bool _Atomic_Compare_exchange_ptr(
    370   volatile Atomic_Pointer *object,
    371   void **old_pointer,
    372   void *new_pointer,
    373   Atomic_Order order_succ,
    374   Atomic_Order order_fail
    375 )
    376 {
    377   return _CPU_atomic_Compare_exchange_ptr( object, old_pointer, new_pointer,
    378     order_succ, order_fail );
    379 }
     141#define _Atomic_Compare_exchange_ptr( obj, expected, desired, succ, fail ) \
     142  _CPU_atomic_Compare_exchange_ptr( obj, expected, desired, succ, fail )
    380143
    381 /**
    382  * @brief Atomically clears an atomic flag.
    383  *
    384  * @param[in, out] object Pointer to the atomic flag object.
    385  * @param[in] order The atomic memory order.
    386  *
    387  */
    388 static inline void _Atomic_Flag_clear(
    389   volatile Atomic_Flag *object,
    390   Atomic_Order order
    391 )
    392 {
    393   _CPU_atomic_Flag_clear( object, order );
    394 }
     144#define _Atomic_Flag_clear( obj, order ) \
     145  _CPU_atomic_Flag_clear( obj, order )
    395146
    396 /**
    397  * @brief Atomically tests and sets an atomic flag.
    398  *
    399  * @param[in, out] object Pointer to the atomic flag object.
    400  * @param[in] order The atomic memory order.
    401  *
    402  * @retval true The atomic flag was already set.
    403  * @retval false Otherwise.
    404  */
    405 static inline bool _Atomic_Flag_test_and_set(
    406   volatile Atomic_Flag *object,
    407   Atomic_Order order
    408 )
    409 {
    410   return _CPU_atomic_Flag_test_and_set( object, order );
    411 }
     147#define _Atomic_Flag_test_and_set( obj, order ) \
     148  _CPU_atomic_Flag_test_and_set( obj, order )
    412149
    413 #ifdef __cplusplus
    414 }
    415 #endif
     150/** @} */
    416151
    417 /**@}*/
    418 #endif
    419 /*  end of include file */
     152#endif /* _RTEMS_SCORE_ATOMIC_H */
Note: See TracChangeset for help on using the changeset viewer.