source: rtems/cpukit/score/include/rtems/score/cpustdatomic.h @ 89f8eab5

4.115
Last change on this file since 89f8eab5 was 89f8eab5, checked in by Sebastian Huber <sebastian.huber@…>, on 05/07/14 at 12:55:37

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

  • Property mode set to 100644
File size: 8.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief Atomic Operations CPU API
5 */
6
7/*
8 * COPYRIGHT (c) 2013 Deng Hengyi.
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifndef _RTEMS_SCORE_CPUSTDATOMIC_H
16#define _RTEMS_SCORE_CPUSTDATOMIC_H
17
18#include <stdint.h>
19
20#if defined(__cplusplus) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 9
21
22/*
23 * The GCC 4.9 ships its own <stdatomic.h> which is not C++ compatible.  The
24 * suggested solution was to include <atomic> in case C++ is used.  This works
25 * at least with GCC 4.9.  See also:
26 *
27 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60932
28 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60940
29 */
30
31#include <atomic>
32
33typedef std::atomic_uint CPU_atomic_Uint;
34
35typedef std::atomic_ulong CPU_atomic_Ulong;
36
37typedef std::atomic_uintptr_t CPU_atomic_Pointer;
38
39typedef std::atomic_flag CPU_atomic_Flag;
40
41#define CPU_ATOMIC_ORDER_RELAXED std::memory_order_relaxed
42
43#define CPU_ATOMIC_ORDER_ACQUIRE std::memory_order_acquire
44
45#define CPU_ATOMIC_ORDER_RELEASE std::memory_order_release
46
47#define CPU_ATOMIC_ORDER_SEQ_CST std::memory_order_seq_cst
48
49#define CPU_ATOMIC_INITIALIZER_UINT( value ) ATOMIC_VAR_INIT( value )
50
51#define CPU_ATOMIC_INITIALIZER_ULONG( value ) ATOMIC_VAR_INIT( value )
52
53#define CPU_ATOMIC_INITIALIZER_PTR( value ) \
54  ATOMIC_VAR_INIT( (uintptr_t) (value) )
55
56#define CPU_ATOMIC_INITIALIZER_FLAG ATOMIC_FLAG_INIT
57
58#define _CPU_atomic_Fence( order ) atomic_thread_fence( order )
59
60#define _CPU_atomic_Init_uint( obj, desired ) \
61  (obj)->store( desired )
62
63#define _CPU_atomic_Init_ulong( obj, desired ) \
64  (obj)->store( desired )
65
66#define _CPU_atomic_Init_ptr( obj, desired ) \
67  (obj)->store( desired )
68
69#define _CPU_atomic_Load_uint( obj, order ) \
70  (obj)->load( order )
71
72#define _CPU_atomic_Load_ulong( obj, order ) \
73  (obj)->load( order )
74
75#define _CPU_atomic_Load_ptr( obj, order ) \
76  (void *) (obj)->load( order )
77
78#define _CPU_atomic_Store_uint( obj, desr, order ) \
79  (obj)->store( desr, order )
80
81#define _CPU_atomic_Store_ulong( obj, desr, order ) \
82  (obj)->store( desr, order )
83
84#define _CPU_atomic_Store_ptr( obj, desr, order ) \
85  (obj)->store( (uintptr_t) desr, order )
86
87#define _CPU_atomic_Fetch_add_uint( obj, arg, order ) \
88  (obj)->fetch_add( arg, order )
89
90#define _CPU_atomic_Fetch_add_ulong( obj, arg, order ) \
91  (obj)->fetch_add( arg, order )
92
93#define _CPU_atomic_Fetch_add_ptr( obj, arg, order ) \
94  (obj)->fetch_add( arg, (uintptr_t) order )
95
96#define _CPU_atomic_Fetch_sub_uint( obj, arg, order ) \
97  (obj)->fetch_sub( arg, order )
98
99#define _CPU_atomic_Fetch_sub_ulong( obj, arg, order ) \
100  (obj)->fetch_sub( arg, order )
101
102#define _CPU_atomic_Fetch_sub_ptr( obj, arg, order ) \
103  (obj)->fetch_sub( arg, (uintptr_t) order )
104
105#define _CPU_atomic_Fetch_or_uint( obj, arg, order ) \
106  (obj)->fetch_or( arg, order )
107
108#define _CPU_atomic_Fetch_or_ulong( obj, arg, order ) \
109  (obj)->fetch_or( arg, order )
110
111#define _CPU_atomic_Fetch_or_ptr( obj, arg, order ) \
112  (obj)->fetch_or( arg, (uintptr_t) order )
113
114#define _CPU_atomic_Fetch_and_uint( obj, arg, order ) \
115  (obj)->fetch_and( arg, order )
116
117#define _CPU_atomic_Fetch_and_ulong( obj, arg, order ) \
118  (obj)->fetch_and( arg, order )
119
120#define _CPU_atomic_Fetch_and_ptr( obj, arg, order ) \
121  (obj)->fetch_and( arg, (uintptr_t) order )
122
123#define _CPU_atomic_Exchange_uint( obj, desr, order ) \
124  (obj)->exchange( desr, order )
125
126#define _CPU_atomic_Exchange_ulong( obj, desr, order ) \
127  (obj)->exchange( desr, order )
128
129#define _CPU_atomic_Exchange_ptr( obj, desr, order ) \
130  (void *) (obj)->exchange( desr, (uintptr_t) order )
131
132#define _CPU_atomic_Compare_exchange_uint( obj, expected, desired, succ, fail ) \
133  (obj)->compare_exchange_strong( expected, desired, succ, fail )
134
135#define _CPU_atomic_Compare_exchange_ulong( obj, expected, desired, succ, fail ) \
136  (obj)->compare_exchange_strong( expected, desired, succ, fail )
137
138#define _CPU_atomic_Compare_exchange_ptr( obj, expected, desired, succ, fail ) \
139  (obj)->compare_exchange_strong( (void **) expected, (uintptr_t) desired, succ, fail )
140
141#define _CPU_atomic_Flag_clear( obj, order ) \
142  (obj)->clear( order )
143
144#define _CPU_atomic_Flag_test_and_set( obj, order ) \
145  (obj)->test_and_set( order )
146
147#else /* __cplusplus */
148
149#include <stdatomic.h>
150
151typedef atomic_uint CPU_atomic_Uint;
152
153typedef atomic_ulong CPU_atomic_Ulong;
154
155typedef atomic_uintptr_t CPU_atomic_Pointer;
156
157typedef atomic_flag CPU_atomic_Flag;
158
159#define CPU_ATOMIC_ORDER_RELAXED memory_order_relaxed
160
161#define CPU_ATOMIC_ORDER_ACQUIRE memory_order_acquire
162
163#define CPU_ATOMIC_ORDER_RELEASE memory_order_release
164
165#define CPU_ATOMIC_ORDER_SEQ_CST memory_order_seq_cst
166
167#define CPU_ATOMIC_INITIALIZER_UINT( value ) ATOMIC_VAR_INIT( value )
168
169#define CPU_ATOMIC_INITIALIZER_ULONG( value ) ATOMIC_VAR_INIT( value )
170
171#define CPU_ATOMIC_INITIALIZER_PTR( value ) \
172  ATOMIC_VAR_INIT( (uintptr_t) (value) )
173
174#define CPU_ATOMIC_INITIALIZER_FLAG ATOMIC_FLAG_INIT
175
176#define _CPU_atomic_Fence( order ) atomic_thread_fence( order )
177
178#define _CPU_atomic_Init_uint( obj, desired ) \
179  atomic_init( obj, desired )
180
181#define _CPU_atomic_Init_ulong( obj, desired ) \
182  atomic_init( obj, desired )
183
184#define _CPU_atomic_Init_ptr( obj, desired ) \
185  atomic_init( obj, (uintptr_t) desired )
186
187#define _CPU_atomic_Load_uint( obj, order ) \
188  atomic_load_explicit( obj, order )
189
190#define _CPU_atomic_Load_ulong( obj, order ) \
191  atomic_load_explicit( obj, order )
192
193#define _CPU_atomic_Load_ptr( obj, order ) \
194  (void *) atomic_load_explicit( obj, order )
195
196#define _CPU_atomic_Store_uint( obj, desr, order ) \
197  atomic_store_explicit( obj, desr, order )
198
199#define _CPU_atomic_Store_ulong( obj, desr, order ) \
200  atomic_store_explicit( obj, desr, order )
201
202#define _CPU_atomic_Store_ptr( obj, desr, order ) \
203  atomic_store_explicit( obj, desr, order )
204
205#define _CPU_atomic_Fetch_add_uint( obj, arg, order ) \
206  atomic_fetch_add_explicit( obj, arg, order )
207
208#define _CPU_atomic_Fetch_add_ulong( obj, arg, order ) \
209  atomic_fetch_add_explicit( obj, arg, order )
210
211#define _CPU_atomic_Fetch_add_ptr( obj, arg, order ) \
212  atomic_fetch_add_explicit( obj, arg, order )
213
214#define _CPU_atomic_Fetch_sub_uint( obj, arg, order ) \
215  atomic_fetch_sub_explicit( obj, arg, order )
216
217#define _CPU_atomic_Fetch_sub_ulong( obj, arg, order ) \
218  atomic_fetch_sub_explicit( obj, arg, order )
219
220#define _CPU_atomic_Fetch_sub_ptr( obj, arg, order ) \
221  atomic_fetch_sub_explicit( obj, arg, order )
222
223#define _CPU_atomic_Fetch_or_uint( obj, arg, order ) \
224  atomic_fetch_or_explicit( obj, arg, order )
225
226#define _CPU_atomic_Fetch_or_ulong( obj, arg, order ) \
227  atomic_fetch_or_explicit( obj, arg, order )
228
229#define _CPU_atomic_Fetch_or_ptr( obj, arg, order ) \
230  atomic_fetch_or_explicit( obj, arg, order )
231
232#define _CPU_atomic_Fetch_and_uint( obj, arg, order ) \
233  atomic_fetch_and_explicit( obj, arg, order )
234
235#define _CPU_atomic_Fetch_and_ulong( obj, arg, order ) \
236  atomic_fetch_and_explicit( obj, arg, order )
237
238#define _CPU_atomic_Fetch_and_ptr( obj, arg, order ) \
239  atomic_fetch_and_explicit( obj, arg, order )
240
241#define _CPU_atomic_Exchange_uint( obj, desr, order ) \
242  atomic_exchange_explicit( obj, desr, order )
243
244#define _CPU_atomic_Exchange_ulong( obj, desr, order ) \
245  atomic_exchange_explicit( obj, desr, order )
246
247#define _CPU_atomic_Exchange_ptr( obj, desr, order ) \
248  atomic_exchange_explicit( obj, desr, order )
249
250#define _CPU_atomic_Compare_exchange_uint( obj, expected, desired, succ, fail ) \
251  atomic_compare_exchange_strong_explicit( obj, expected, desired, succ, fail )
252
253#define _CPU_atomic_Compare_exchange_ulong( obj, expected, desired, succ, fail ) \
254  atomic_compare_exchange_strong_explicit( obj, expected, desired, succ, fail )
255
256#define _CPU_atomic_Compare_exchange_ptr( obj, expected, desired, succ, fail ) \
257  atomic_compare_exchange_strong_explicit( obj, expected, desired, succ, fail )
258
259#define _CPU_atomic_Flag_clear( obj, order ) \
260  atomic_flag_clear_explicit( obj, order )
261
262#define _CPU_atomic_Flag_test_and_set( obj, order ) \
263  atomic_flag_test_and_set_explicit( obj, order )
264
265#endif /* __cplusplus */
266
267#endif /* _RTEMS_SCORE_CPUSTDATOMIC_H */
Note: See TracBrowser for help on using the repository browser.