source: rtems/cpukit/score/include/rtems/score/cpustdatomic.h @ 7183f1cd

4.11
Last change on this file since 7183f1cd was 7183f1cd, checked in by Sebastian Huber <sebastian.huber@…>, on Mar 5, 2015 at 10:51:25 AM

score: Add compiler memory barrier to atomic ops

  • Property mode set to 100644
File size: 16.8 KB
Line 
1/**
2 * @file
3 *
4 * @brief Atomic Operations CPU API
5 */
6
7/*
8 * COPYRIGHT (c) 2013 Deng Hengyi.
9 * Copyright (c) 2015 embedded brains GmbH.
10 *
11 * The license and distribution terms for this file may be
12 * found in the file LICENSE in this distribution or at
13 * http://www.rtems.org/license/LICENSE.
14 */
15
16#ifndef _RTEMS_SCORE_CPUSTDATOMIC_H
17#define _RTEMS_SCORE_CPUSTDATOMIC_H
18
19#include <rtems/score/basedefs.h>
20
21#ifdef RTEMS_SMP
22  #if defined(__cplusplus) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 9
23    /*
24     * The GCC 4.9 ships its own <stdatomic.h> which is not C++ compatible.  The
25     * suggested solution was to include <atomic> in case C++ is used.  This works
26     * at least with GCC 4.9.  See also:
27     *
28     * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60932
29     * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60940
30     */
31    #include <atomic>
32    #define _RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC
33  #else
34    #include <stdatomic.h>
35    #define _RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC
36  #endif
37#else
38  #include <rtems/score/isrlevel.h>
39#endif
40
41#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
42
43typedef std::atomic_uint CPU_atomic_Uint;
44
45typedef std::atomic_ulong CPU_atomic_Ulong;
46
47typedef std::atomic_uintptr_t CPU_atomic_Pointer;
48
49typedef std::atomic_flag CPU_atomic_Flag;
50
51typedef std::memory_order CPU_atomic_Order;
52
53#define CPU_ATOMIC_ORDER_RELAXED std::memory_order_relaxed
54
55#define CPU_ATOMIC_ORDER_ACQUIRE std::memory_order_acquire
56
57#define CPU_ATOMIC_ORDER_RELEASE std::memory_order_release
58
59#define CPU_ATOMIC_ORDER_SEQ_CST std::memory_order_seq_cst
60
61#define CPU_ATOMIC_INITIALIZER_UINT( value ) ATOMIC_VAR_INIT( value )
62
63#define CPU_ATOMIC_INITIALIZER_ULONG( value ) ATOMIC_VAR_INIT( value )
64
65#define CPU_ATOMIC_INITIALIZER_PTR( value ) \
66  ATOMIC_VAR_INIT( (uintptr_t) (value) )
67
68#define CPU_ATOMIC_INITIALIZER_FLAG ATOMIC_FLAG_INIT
69
70#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
71
72typedef atomic_uint CPU_atomic_Uint;
73
74typedef atomic_ulong CPU_atomic_Ulong;
75
76typedef atomic_uintptr_t CPU_atomic_Pointer;
77
78typedef atomic_flag CPU_atomic_Flag;
79
80typedef memory_order CPU_atomic_Order;
81
82#define CPU_ATOMIC_ORDER_RELAXED memory_order_relaxed
83
84#define CPU_ATOMIC_ORDER_ACQUIRE memory_order_acquire
85
86#define CPU_ATOMIC_ORDER_RELEASE memory_order_release
87
88#define CPU_ATOMIC_ORDER_SEQ_CST memory_order_seq_cst
89
90#define CPU_ATOMIC_INITIALIZER_UINT( value ) ATOMIC_VAR_INIT( value )
91
92#define CPU_ATOMIC_INITIALIZER_ULONG( value ) ATOMIC_VAR_INIT( value )
93
94#define CPU_ATOMIC_INITIALIZER_PTR( value ) \
95  ATOMIC_VAR_INIT( (uintptr_t) (value) )
96
97#define CPU_ATOMIC_INITIALIZER_FLAG ATOMIC_FLAG_INIT
98
99#else
100
101typedef unsigned int CPU_atomic_Uint;
102
103typedef unsigned long CPU_atomic_Ulong;
104
105typedef uintptr_t CPU_atomic_Pointer;
106
107typedef bool CPU_atomic_Flag;
108
109typedef int CPU_atomic_Order;
110
111#define CPU_ATOMIC_ORDER_RELAXED 0
112
113#define CPU_ATOMIC_ORDER_ACQUIRE 2
114
115#define CPU_ATOMIC_ORDER_RELEASE 3
116
117#define CPU_ATOMIC_ORDER_SEQ_CST 5
118
119#define CPU_ATOMIC_INITIALIZER_UINT( value ) ( value )
120
121#define CPU_ATOMIC_INITIALIZER_ULONG( value ) ( value )
122
123#define CPU_ATOMIC_INITIALIZER_PTR( value ) ( (uintptr_t) (value) )
124
125#define CPU_ATOMIC_INITIALIZER_FLAG false
126
127#endif
128
129static inline void _CPU_atomic_Fence( CPU_atomic_Order order )
130{
131#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
132  std::atomic_thread_fence( order );
133#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
134  atomic_thread_fence( order );
135#else
136  (void) order;
137  RTEMS_COMPILER_MEMORY_BARRIER();
138#endif
139}
140
141static inline void _CPU_atomic_Init_uint( CPU_atomic_Uint *obj, unsigned int desired )
142{
143#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
144  obj->store( desired );
145#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
146  atomic_init( obj, desired );
147#else
148  *obj = desired;
149#endif
150}
151
152static inline void _CPU_atomic_Init_ulong( CPU_atomic_Ulong *obj, unsigned long desired )
153{
154#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
155  obj->store( desired );
156#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
157  atomic_init( obj, desired );
158#else
159  *obj = desired;
160#endif
161}
162
163static inline void _CPU_atomic_Init_ptr( CPU_atomic_Pointer *obj, void *desired )
164{
165#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
166  obj->store( (uintptr_t) desired );
167#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
168  atomic_init( obj, (uintptr_t) desired );
169#else
170  *obj = (uintptr_t) desired;
171#endif
172}
173
174static inline unsigned int _CPU_atomic_Load_uint( const CPU_atomic_Uint *obj, CPU_atomic_Order order )
175{
176#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
177  return obj->load( order );
178#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
179  return atomic_load_explicit( obj, order );
180#else
181  (void) order;
182  RTEMS_COMPILER_MEMORY_BARRIER();
183  return *obj;
184#endif
185}
186
187static inline unsigned long _CPU_atomic_Load_ulong( const CPU_atomic_Ulong *obj, CPU_atomic_Order order )
188{
189#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
190  return obj->load( order );
191#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
192  return atomic_load_explicit( obj, order );
193#else
194  (void) order;
195  RTEMS_COMPILER_MEMORY_BARRIER();
196  return *obj;
197#endif
198}
199
200static inline void *_CPU_atomic_Load_ptr( const CPU_atomic_Pointer *obj, CPU_atomic_Order order )
201{
202#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
203  return (void *) obj->load( order );
204#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
205  return (void *) atomic_load_explicit( obj, order );
206#else
207  (void) order;
208  RTEMS_COMPILER_MEMORY_BARRIER();
209  return (void *) *obj;
210#endif
211}
212
213static inline void _CPU_atomic_Store_uint( CPU_atomic_Uint *obj, unsigned int desired, CPU_atomic_Order order )
214{
215#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
216  obj->store( desired );
217#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
218  atomic_store_explicit( obj, desired, order );
219#else
220  (void) order;
221  *obj = desired;
222  RTEMS_COMPILER_MEMORY_BARRIER();
223#endif
224}
225
226static inline void _CPU_atomic_Store_ulong( CPU_atomic_Ulong *obj, unsigned long desired, CPU_atomic_Order order )
227{
228#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
229  obj->store( desired );
230#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
231  atomic_store_explicit( obj, desired, order );
232#else
233  (void) order;
234  *obj = desired;
235  RTEMS_COMPILER_MEMORY_BARRIER();
236#endif
237}
238
239static inline void _CPU_atomic_Store_ptr( CPU_atomic_Pointer *obj, void *desired, CPU_atomic_Order order )
240{
241#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
242  obj->store( (uintptr_t) desired );
243#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
244  atomic_store_explicit( obj, (uintptr_t) desired, order );
245#else
246  (void) order;
247  *obj = (uintptr_t) desired;
248  RTEMS_COMPILER_MEMORY_BARRIER();
249#endif
250}
251
252static inline unsigned int _CPU_atomic_Fetch_add_uint( CPU_atomic_Uint *obj, unsigned int arg, CPU_atomic_Order order )
253{
254#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
255  return obj->fetch_add( arg, order );
256#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
257  return atomic_fetch_add_explicit( obj, arg, order );
258#else
259  unsigned int val;
260  ISR_Level level;
261
262  (void) order;
263  _ISR_Disable( level );
264  val = *obj;
265  *obj = val + arg;
266  _ISR_Enable( level );
267
268  return val;
269#endif
270}
271
272static inline unsigned long _CPU_atomic_Fetch_add_ulong( CPU_atomic_Ulong *obj, unsigned long arg, CPU_atomic_Order order )
273{
274#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
275  return obj->fetch_add( arg, order );
276#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
277  return atomic_fetch_add_explicit( obj, arg, order );
278#else
279  unsigned long val;
280  ISR_Level level;
281
282  (void) order;
283  _ISR_Disable( level );
284  val = *obj;
285  *obj = val + arg;
286  _ISR_Enable( level );
287
288  return val;
289#endif
290}
291
292static inline void *_CPU_atomic_Fetch_add_ptr( CPU_atomic_Pointer *obj, void *arg, CPU_atomic_Order order )
293{
294#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
295  return (void *) obj->fetch_add( (uintptr_t) arg, order );
296#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
297  return (void *) atomic_fetch_add_explicit( obj, (uintptr_t) arg, order );
298#else
299  uintptr_t val;
300  ISR_Level level;
301
302  (void) order;
303  _ISR_Disable( level );
304  val = *obj;
305  *obj = val + (uintptr_t) arg;
306  _ISR_Enable( level );
307
308  return (void *) val;
309#endif
310}
311
312static inline unsigned int _CPU_atomic_Fetch_sub_uint( CPU_atomic_Uint *obj, unsigned int arg, CPU_atomic_Order order )
313{
314#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
315  return obj->fetch_sub( arg, order );
316#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
317  return atomic_fetch_sub_explicit( obj, arg, order );
318#else
319  unsigned int val;
320  ISR_Level level;
321
322  (void) order;
323  _ISR_Disable( level );
324  val = *obj;
325  *obj = val - arg;
326  _ISR_Enable( level );
327
328  return val;
329#endif
330}
331
332static inline unsigned long _CPU_atomic_Fetch_sub_ulong( CPU_atomic_Ulong *obj, unsigned long arg, CPU_atomic_Order order )
333{
334#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
335  return obj->fetch_sub( arg, order );
336#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
337  return atomic_fetch_sub_explicit( obj, arg, order );
338#else
339  unsigned long val;
340  ISR_Level level;
341
342  (void) order;
343  _ISR_Disable( level );
344  val = *obj;
345  *obj = val - arg;
346  _ISR_Enable( level );
347
348  return val;
349#endif
350}
351
352static inline void *_CPU_atomic_Fetch_sub_ptr( CPU_atomic_Pointer *obj, void *arg, CPU_atomic_Order order )
353{
354#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
355  return (void *) obj->fetch_sub( (uintptr_t) arg, order );
356#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
357  return (void *) atomic_fetch_sub_explicit( obj, (uintptr_t) arg, order );
358#else
359  unsigned int val;
360  ISR_Level level;
361
362  (void) order;
363  _ISR_Disable( level );
364  val = *obj;
365  *obj = val - (uintptr_t) arg;
366  _ISR_Enable( level );
367
368  return (void *) val;
369#endif
370}
371
372static inline unsigned int _CPU_atomic_Fetch_or_uint( CPU_atomic_Uint *obj, unsigned int arg, CPU_atomic_Order order )
373{
374#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
375  return obj->fetch_or( arg, order );
376#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
377  return atomic_fetch_or_explicit( obj, arg, order );
378#else
379  unsigned int val;
380  ISR_Level level;
381
382  (void) order;
383  _ISR_Disable( level );
384  val = *obj;
385  *obj = val | arg;
386  _ISR_Enable( level );
387
388  return val;
389#endif
390}
391
392static inline unsigned long _CPU_atomic_Fetch_or_ulong( CPU_atomic_Ulong *obj, unsigned long arg, CPU_atomic_Order order )
393{
394#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
395  return obj->fetch_or( arg, order );
396#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
397  return atomic_fetch_or_explicit( obj, arg, order );
398#else
399  unsigned long val;
400  ISR_Level level;
401
402  (void) order;
403  _ISR_Disable( level );
404  val = *obj;
405  *obj = val | arg;
406  _ISR_Enable( level );
407
408  return val;
409#endif
410}
411
412static inline void *_CPU_atomic_Fetch_or_ptr( CPU_atomic_Pointer *obj, void *arg, CPU_atomic_Order order )
413{
414#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
415  return (void *) obj->fetch_or( (uintptr_t) arg, order );
416#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
417  return (void *) atomic_fetch_or_explicit( obj, (uintptr_t) arg, order );
418#else
419  uintptr_t val;
420  ISR_Level level;
421
422  (void) order;
423  _ISR_Disable( level );
424  val = *obj;
425  *obj = val | (uintptr_t) arg;
426  _ISR_Enable( level );
427
428  return (void *) val;
429#endif
430}
431
432static inline unsigned int _CPU_atomic_Fetch_and_uint( CPU_atomic_Uint *obj, unsigned int arg, CPU_atomic_Order order )
433{
434#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
435  return obj->fetch_and( arg, order );
436#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
437  return atomic_fetch_and_explicit( obj, arg, order );
438#else
439  unsigned int val;
440  ISR_Level level;
441
442  (void) order;
443  _ISR_Disable( level );
444  val = *obj;
445  *obj = val & arg;
446  _ISR_Enable( level );
447
448  return val;
449#endif
450}
451
452static inline unsigned long _CPU_atomic_Fetch_and_ulong( CPU_atomic_Ulong *obj, unsigned long arg, CPU_atomic_Order order )
453{
454#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
455  return obj->fetch_and( arg, order );
456#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
457  return atomic_fetch_and_explicit( obj, arg, order );
458#else
459  unsigned long val;
460  ISR_Level level;
461
462  (void) order;
463  _ISR_Disable( level );
464  val = *obj;
465  *obj = val & arg;
466  _ISR_Enable( level );
467
468  return val;
469#endif
470}
471
472static inline void *_CPU_atomic_Fetch_and_ptr( CPU_atomic_Pointer *obj, void *arg, CPU_atomic_Order order )
473{
474#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
475  return (void *) obj->fetch_and( (uintptr_t) arg, order );
476#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
477  return (void *) atomic_fetch_and_explicit( obj, (uintptr_t) arg, order );
478#else
479  uintptr_t val;
480  ISR_Level level;
481
482  (void) order;
483  _ISR_Disable( level );
484  val = *obj;
485  *obj = val & (uintptr_t) arg;
486  _ISR_Enable( level );
487
488  return (void *) val;
489#endif
490}
491
492static inline unsigned int _CPU_atomic_Exchange_uint( CPU_atomic_Uint *obj, unsigned int desired, CPU_atomic_Order order )
493{
494#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
495  return obj->exchange( desired, order );
496#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
497  return atomic_exchange_explicit( obj, desired, order );
498#else
499  unsigned int val;
500  ISR_Level level;
501
502  (void) order;
503  _ISR_Disable( level );
504  val = *obj;
505  *obj = desired;
506  _ISR_Enable( level );
507
508  return val;
509#endif
510}
511
512static inline unsigned long _CPU_atomic_Exchange_ulong( CPU_atomic_Ulong *obj, unsigned long desired, CPU_atomic_Order order )
513{
514#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
515  return obj->exchange( desired, order );
516#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
517  return atomic_exchange_explicit( obj, desired, order );
518#else
519  unsigned long val;
520  ISR_Level level;
521
522  (void) order;
523  _ISR_Disable( level );
524  val = *obj;
525  *obj = desired;
526  _ISR_Enable( level );
527
528  return val;
529#endif
530}
531
532static inline void *_CPU_atomic_Exchange_ptr( CPU_atomic_Pointer *obj, void *desired, CPU_atomic_Order order )
533{
534#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
535  return (void *) obj->exchange( (uintptr_t) desired, order );
536#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
537  return (void *) atomic_exchange_explicit( obj, (uintptr_t) desired, order );
538#else
539  uintptr_t val;
540  ISR_Level level;
541
542  (void) order;
543  _ISR_Disable( level );
544  val = *obj;
545  *obj = (uintptr_t) desired;
546  _ISR_Enable( level );
547
548  return (void *) val;
549#endif
550}
551
552static 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 )
553{
554#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
555  return obj->compare_exchange_strong( *expected, desired, succ, fail );
556#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
557  return atomic_compare_exchange_strong_explicit( obj, expected, desired, succ, fail );
558#else
559  bool success;
560  ISR_Level level;
561
562  (void) succ;
563  (void) fail;
564  _ISR_Disable( level );
565  success = *obj == *expected;
566  if ( success ) {
567    *obj = desired;
568  }
569  _ISR_Enable( level );
570
571  return success;
572#endif
573}
574
575static 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 )
576{
577#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
578  return obj->compare_exchange_strong( *expected, desired, succ, fail );
579#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
580  return atomic_compare_exchange_strong_explicit( obj, expected, desired, succ, fail );
581#else
582  bool success;
583  ISR_Level level;
584
585  (void) succ;
586  (void) fail;
587  _ISR_Disable( level );
588  success = *obj == *expected;
589  if ( success ) {
590    *obj = desired;
591  }
592  _ISR_Enable( level );
593
594  return success;
595#endif
596}
597
598static inline bool _CPU_atomic_Compare_exchange_ptr( CPU_atomic_Pointer *obj, void **expected, void *desired, CPU_atomic_Order succ, CPU_atomic_Order fail )
599{
600#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
601  return obj->compare_exchange_strong( *(uintptr_t *) expected, (uintptr_t) desired, succ, fail );
602#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
603  return atomic_compare_exchange_strong_explicit( obj, (uintptr_t *) expected, (uintptr_t) desired, succ, fail );
604#else
605  bool success;
606  ISR_Level level;
607
608  (void) succ;
609  (void) fail;
610  _ISR_Disable( level );
611  success = *obj == (uintptr_t) *expected;
612  if ( success ) {
613    *obj = (uintptr_t) desired;
614  }
615  _ISR_Enable( level );
616
617  return success;
618#endif
619}
620
621static inline void _CPU_atomic_Flag_clear( CPU_atomic_Flag *obj, CPU_atomic_Order order )
622{
623#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
624  obj->clear( order );
625#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
626  atomic_flag_clear_explicit( obj, order );
627#else
628  (void) order;
629  *obj = false;
630#endif
631}
632
633static inline bool _CPU_atomic_Flag_test_and_set( CPU_atomic_Flag *obj, CPU_atomic_Order order )
634{
635#if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
636  return obj->test_and_set( order );
637#elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
638  return atomic_flag_test_and_set_explicit( obj, order );
639#else
640  bool flag;
641  ISR_Level level;
642
643  (void) order;
644  _ISR_Disable( level );
645  flag = *obj;
646  *obj = true;
647  _ISR_Enable( level );
648
649  return flag;
650#endif
651}
652
653#endif /* _RTEMS_SCORE_CPUSTDATOMIC_H */
Note: See TracBrowser for help on using the repository browser.