Changeset 8d296cd5 in rtems


Ignore:
Timestamp:
Sep 26, 2015, 11:03:16 AM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
aee6a1d0
Parents:
5458bff
git-author:
Sebastian Huber <sebastian.huber@…> (09/26/15 11:03:16)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/26/15 19:23:53)
Message:

score: Use uintptr_t for atomic pointer operations

Do not obfuscate the standard API.

Files:
6 edited

Legend:

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

    r5458bff r8d296cd5  
    3939typedef CPU_atomic_Ulong Atomic_Ulong;
    4040
    41 typedef CPU_atomic_Pointer Atomic_Pointer;
     41typedef CPU_atomic_Uintptr Atomic_Uintptr;
    4242
    4343typedef CPU_atomic_Flag Atomic_Flag;
     
    5959#define ATOMIC_INITIALIZER_ULONG( value ) CPU_ATOMIC_INITIALIZER_ULONG( value )
    6060
    61 #define ATOMIC_INITIALIZER_PTR( value ) CPU_ATOMIC_INITIALIZER_PTR( value )
     61#define ATOMIC_INITIALIZER_UINTPTR( value ) CPU_ATOMIC_INITIALIZER_UINTPTR( value )
    6262
    6363#define ATOMIC_INITIALIZER_FLAG CPU_ATOMIC_INITIALIZER_FLAG
     
    7171  _CPU_atomic_Init_ulong( obj, desired )
    7272
    73 #define _Atomic_Init_ptr( obj, desired ) \
    74   _CPU_atomic_Init_ptr( obj, desired )
     73#define _Atomic_Init_uintptr( obj, desired ) \
     74  _CPU_atomic_Init_uintptr( obj, desired )
    7575
    7676#define _Atomic_Load_uint( obj, order ) \
     
    8080  _CPU_atomic_Load_ulong( obj, order )
    8181
    82 #define _Atomic_Load_ptr( obj, order ) \
    83   _CPU_atomic_Load_ptr( obj, order )
     82#define _Atomic_Load_uintptr( obj, order ) \
     83  _CPU_atomic_Load_uintptr( obj, order )
    8484
    8585#define _Atomic_Store_uint( obj, desr, order ) \
     
    8989  _CPU_atomic_Store_ulong( obj, desr, order )
    9090
    91 #define _Atomic_Store_ptr( obj, desr, order ) \
    92   _CPU_atomic_Store_ptr( obj, desr, order )
     91#define _Atomic_Store_uintptr( obj, desr, order ) \
     92  _CPU_atomic_Store_uintptr( obj, desr, order )
    9393
    9494#define _Atomic_Fetch_add_uint( obj, arg, order ) \
     
    9898  _CPU_atomic_Fetch_add_ulong( obj, arg, order )
    9999
    100 #define _Atomic_Fetch_add_ptr( obj, arg, order ) \
    101   _CPU_atomic_Fetch_add_ptr( obj, arg, order )
     100#define _Atomic_Fetch_add_uintptr( obj, arg, order ) \
     101  _CPU_atomic_Fetch_add_uintptr( obj, arg, order )
    102102
    103103#define _Atomic_Fetch_sub_uint( obj, arg, order ) \
     
    107107  _CPU_atomic_Fetch_sub_ulong( obj, arg, order )
    108108
    109 #define _Atomic_Fetch_sub_ptr( obj, arg, order ) \
    110   _CPU_atomic_Fetch_sub_ptr( obj, arg, order )
     109#define _Atomic_Fetch_sub_uintptr( obj, arg, order ) \
     110  _CPU_atomic_Fetch_sub_uintptr( obj, arg, order )
    111111
    112112#define _Atomic_Fetch_or_uint( obj, arg, order ) \
     
    116116  _CPU_atomic_Fetch_or_ulong( obj, arg, order )
    117117
    118 #define _Atomic_Fetch_or_ptr( obj, arg, order ) \
    119   _CPU_atomic_Fetch_or_ptr( obj, arg, order )
     118#define _Atomic_Fetch_or_uintptr( obj, arg, order ) \
     119  _CPU_atomic_Fetch_or_uintptr( obj, arg, order )
    120120
    121121#define _Atomic_Fetch_and_uint( obj, arg, order ) \
     
    125125  _CPU_atomic_Fetch_and_ulong( obj, arg, order )
    126126
    127 #define _Atomic_Fetch_and_ptr( obj, arg, order ) \
    128   _CPU_atomic_Fetch_and_ptr( obj, arg, order )
     127#define _Atomic_Fetch_and_uintptr( obj, arg, order ) \
     128  _CPU_atomic_Fetch_and_uintptr( obj, arg, order )
    129129
    130130#define _Atomic_Exchange_uint( obj, desr, order ) \
     
    134134  _CPU_atomic_Exchange_ulong( obj, desr, order )
    135135
    136 #define _Atomic_Exchange_ptr( obj, desr, order ) \
    137   _CPU_atomic_Exchange_ptr( obj, desr, order )
     136#define _Atomic_Exchange_uintptr( obj, desr, order ) \
     137  _CPU_atomic_Exchange_uintptr( obj, desr, order )
    138138
    139139#define _Atomic_Compare_exchange_uint( obj, expected, desired, succ, fail ) \
     
    143143  _CPU_atomic_Compare_exchange_ulong( obj, expected, desired, succ, fail )
    144144
    145 #define _Atomic_Compare_exchange_ptr( obj, expected, desired, succ, fail ) \
    146   _CPU_atomic_Compare_exchange_ptr( obj, expected, desired, succ, fail )
     145#define _Atomic_Compare_exchange_uintptr( obj, expected, desired, succ, fail ) \
     146  _CPU_atomic_Compare_exchange_uintptr( obj, expected, desired, succ, fail )
    147147
    148148#define _Atomic_Flag_clear( obj, order ) \
  • cpukit/score/include/rtems/score/cpustdatomic.h

    r5458bff r8d296cd5  
    4646typedef std::atomic_ulong CPU_atomic_Ulong;
    4747
    48 typedef std::atomic_uintptr_t CPU_atomic_Pointer;
     48typedef std::atomic_uintptr_t CPU_atomic_Uintptr;
    4949
    5050typedef std::atomic_flag CPU_atomic_Flag;
     
    6666#define CPU_ATOMIC_INITIALIZER_ULONG( value ) ATOMIC_VAR_INIT( value )
    6767
    68 #define CPU_ATOMIC_INITIALIZER_PTR( value ) \
    69   ATOMIC_VAR_INIT( (uintptr_t) (value) )
     68#define CPU_ATOMIC_INITIALIZER_UINTPTR( value ) ATOMIC_VAR_INIT( value )
    7069
    7170#define CPU_ATOMIC_INITIALIZER_FLAG ATOMIC_FLAG_INIT
     
    7776typedef atomic_ulong CPU_atomic_Ulong;
    7877
    79 typedef atomic_uintptr_t CPU_atomic_Pointer;
     78typedef atomic_uintptr_t CPU_atomic_Uintptr;
    8079
    8180typedef atomic_flag CPU_atomic_Flag;
     
    9796#define CPU_ATOMIC_INITIALIZER_ULONG( value ) ATOMIC_VAR_INIT( value )
    9897
    99 #define CPU_ATOMIC_INITIALIZER_PTR( value ) \
    100   ATOMIC_VAR_INIT( (uintptr_t) (value) )
     98#define CPU_ATOMIC_INITIALIZER_UINTPTR( value ) ATOMIC_VAR_INIT( value )
    10199
    102100#define CPU_ATOMIC_INITIALIZER_FLAG ATOMIC_FLAG_INIT
     
    108106typedef unsigned long CPU_atomic_Ulong;
    109107
    110 typedef uintptr_t CPU_atomic_Pointer;
     108typedef uintptr_t CPU_atomic_Uintptr;
    111109
    112110typedef bool CPU_atomic_Flag;
     
    128126#define CPU_ATOMIC_INITIALIZER_ULONG( value ) ( value )
    129127
    130 #define CPU_ATOMIC_INITIALIZER_PTR( value ) ( (uintptr_t) (value) )
     128#define CPU_ATOMIC_INITIALIZER_UINTPTR( value ) ( value )
    131129
    132130#define CPU_ATOMIC_INITIALIZER_FLAG false
     
    168166}
    169167
    170 static inline void _CPU_atomic_Init_ptr( CPU_atomic_Pointer *obj, void *desired )
    171 {
    172 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
    173   obj->store( (uintptr_t) desired );
    174 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
    175   atomic_init( obj, (uintptr_t) desired );
    176 #else
    177   *obj = (uintptr_t) desired;
     168static inline void _CPU_atomic_Init_uintptr( CPU_atomic_Uintptr *obj, uintptr_t desired )
     169{
     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 );
     174#else
     175  *obj = desired;
    178176#endif
    179177}
     
    213211}
    214212
    215 static inline void *_CPU_atomic_Load_ptr( const CPU_atomic_Pointer *obj, CPU_atomic_Order order )
    216 {
    217 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
    218   return (void *) obj->load( order );
    219 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
    220   return (void *) atomic_load_explicit( obj, order );
     213static inline uintptr_t _CPU_atomic_Load_uintptr( const CPU_atomic_Uintptr *obj, CPU_atomic_Order order )
     214{
     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 );
    221219#else
    222220  uintptr_t val;
     
    226224  RTEMS_COMPILER_MEMORY_BARRIER();
    227225
    228   return (void *) val;
     226  return val;
    229227#endif
    230228}
     
    256254}
    257255
    258 static inline void _CPU_atomic_Store_ptr( CPU_atomic_Pointer *obj, void *desired, CPU_atomic_Order order )
    259 {
    260 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
    261   obj->store( (uintptr_t) desired );
    262 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
    263   atomic_store_explicit( obj, (uintptr_t) desired, order );
     256static inline void _CPU_atomic_Store_uintptr( CPU_atomic_Uintptr *obj, uintptr_t desired, CPU_atomic_Order order )
     257{
     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 );
    264262#else
    265263  (void) order;
    266264  RTEMS_COMPILER_MEMORY_BARRIER();
    267   *obj = (uintptr_t) desired;
     265  *obj = desired;
    268266#endif
    269267}
     
    309307}
    310308
    311 static inline void *_CPU_atomic_Fetch_add_ptr( CPU_atomic_Pointer *obj, void *arg, CPU_atomic_Order order )
    312 {
    313 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
    314   return (void *) obj->fetch_add( (uintptr_t) arg, order );
    315 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
    316   return (void *) atomic_fetch_add_explicit( obj, (uintptr_t) arg, order );
     309static inline uintptr_t _CPU_atomic_Fetch_add_uintptr( CPU_atomic_Uintptr *obj, uintptr_t arg, CPU_atomic_Order order )
     310{
     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 );
    317315#else
    318316  uintptr_t val;
     
    322320  _ISR_Disable( level );
    323321  val = *obj;
    324   *obj = val + (uintptr_t) arg;
    325   _ISR_Enable( level );
    326 
    327   return (void *) val;
     322  *obj = val + arg;
     323  _ISR_Enable( level );
     324
     325  return val;
    328326#endif
    329327}
     
    369367}
    370368
    371 static inline void *_CPU_atomic_Fetch_sub_ptr( CPU_atomic_Pointer *obj, void *arg, CPU_atomic_Order order )
    372 {
    373 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
    374   return (void *) obj->fetch_sub( (uintptr_t) arg, order );
    375 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
    376   return (void *) atomic_fetch_sub_explicit( obj, (uintptr_t) arg, order );
     369static inline uintptr_t _CPU_atomic_Fetch_sub_uintptr( CPU_atomic_Uintptr *obj, uintptr_t arg, CPU_atomic_Order order )
     370{
     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 );
    377375#else
    378376  uintptr_t val;
     
    382380  _ISR_Disable( level );
    383381  val = *obj;
    384   *obj = val - (uintptr_t) arg;
    385   _ISR_Enable( level );
    386 
    387   return (void *) val;
     382  *obj = val - arg;
     383  _ISR_Enable( level );
     384
     385  return val;
    388386#endif
    389387}
     
    429427}
    430428
    431 static inline void *_CPU_atomic_Fetch_or_ptr( CPU_atomic_Pointer *obj, void *arg, CPU_atomic_Order order )
    432 {
    433 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
    434   return (void *) obj->fetch_or( (uintptr_t) arg, order );
    435 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
    436   return (void *) atomic_fetch_or_explicit( obj, (uintptr_t) arg, order );
     429static inline uintptr_t _CPU_atomic_Fetch_or_uintptr( CPU_atomic_Uintptr *obj, uintptr_t arg, CPU_atomic_Order order )
     430{
     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 );
    437435#else
    438436  uintptr_t val;
     
    442440  _ISR_Disable( level );
    443441  val = *obj;
    444   *obj = val | (uintptr_t) arg;
    445   _ISR_Enable( level );
    446 
    447   return (void *) val;
     442  *obj = val | arg;
     443  _ISR_Enable( level );
     444
     445  return val;
    448446#endif
    449447}
     
    489487}
    490488
    491 static inline void *_CPU_atomic_Fetch_and_ptr( CPU_atomic_Pointer *obj, void *arg, CPU_atomic_Order order )
    492 {
    493 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
    494   return (void *) obj->fetch_and( (uintptr_t) arg, order );
    495 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
    496   return (void *) atomic_fetch_and_explicit( obj, (uintptr_t) arg, order );
     489static inline uintptr_t _CPU_atomic_Fetch_and_uintptr( CPU_atomic_Uintptr *obj, uintptr_t arg, CPU_atomic_Order order )
     490{
     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 );
    497495#else
    498496  uintptr_t val;
     
    502500  _ISR_Disable( level );
    503501  val = *obj;
    504   *obj = val & (uintptr_t) arg;
    505   _ISR_Enable( level );
    506 
    507   return (void *) val;
     502  *obj = val & arg;
     503  _ISR_Enable( level );
     504
     505  return val;
    508506#endif
    509507}
     
    549547}
    550548
    551 static inline void *_CPU_atomic_Exchange_ptr( CPU_atomic_Pointer *obj, void *desired, CPU_atomic_Order order )
    552 {
    553 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
    554   return (void *) obj->exchange( (uintptr_t) desired, order );
    555 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
    556   return (void *) atomic_exchange_explicit( obj, (uintptr_t) desired, order );
     549static inline uintptr_t _CPU_atomic_Exchange_uintptr( CPU_atomic_Uintptr *obj, uintptr_t desired, CPU_atomic_Order order )
     550{
     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 );
    557555#else
    558556  uintptr_t val;
     
    562560  _ISR_Disable( level );
    563561  val = *obj;
    564   *obj = (uintptr_t) desired;
    565   _ISR_Enable( level );
    566 
    567   return (void *) val;
     562  *obj = desired;
     563  _ISR_Enable( level );
     564
     565  return val;
    568566#endif
    569567}
     
    623621}
    624622
    625 static inline bool _CPU_atomic_Compare_exchange_ptr( CPU_atomic_Pointer *obj, void **expected, void *desired, CPU_atomic_Order succ, CPU_atomic_Order fail )
    626 {
    627 #if defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_ATOMIC)
    628   return obj->compare_exchange_strong( *(uintptr_t *) expected, (uintptr_t) desired, succ, fail );
    629 #elif defined(_RTEMS_SCORE_CPUSTDATOMIC_USE_STDATOMIC)
    630   return atomic_compare_exchange_strong_explicit( obj, (uintptr_t *) expected, (uintptr_t) desired, succ, fail );
     623static 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 )
     624{
     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 );
    631629#else
    632630  bool success;
     
    638636  _ISR_Disable( level );
    639637  actual = *obj;
    640   success = ( actual == (uintptr_t) *expected );
     638  success = ( actual == *expected );
    641639  if ( success ) {
    642     *obj = (uintptr_t) desired;
     640    *obj = desired;
    643641  } else {
    644     *expected = (void *) actual;
     642    *expected = actual;
    645643  }
    646644  _ISR_Enable( level );
  • testsuites/smptests/smpatomic01/init.c

    r5458bff r8d296cd5  
    3737typedef struct {
    3838  rtems_test_parallel_context base;
    39   Atomic_Uint atomic_int_value;
    4039  Atomic_Ulong atomic_value;
    4140  unsigned long per_worker_value[CPU_COUNT];
  • testsuites/sptests/spatomic01/init.c

    r5458bff r8d296cd5  
    2828
    2929typedef struct {
    30   Atomic_Uint atomic_int_value;
    31   Atomic_Ulong atomic_value;
     30  Atomic_Uint uint_atomic;
     31  Atomic_Uintptr uintptr_atomic;
     32  Atomic_Ulong ulong_atomic;
    3233} test_context;
    3334
     
    4445  static Atomic_Uint static_uint   = ATOMIC_INITIALIZER_UINT(UINT_CONSTANT);
    4546  static Atomic_Ulong static_ulong = ATOMIC_INITIALIZER_ULONG(0xdeadbeefUL);
    46   static Atomic_Pointer static_ptr = ATOMIC_INITIALIZER_PTR(&static_ptr);
     47  static Atomic_Uintptr static_uintptr =
     48    ATOMIC_INITIALIZER_UINTPTR((uintptr_t) &static_uintptr);
    4749  static Atomic_Flag static_flag  = ATOMIC_INITIALIZER_FLAG;
    4850
    4951  Atomic_Uint stack_uint;
    5052  Atomic_Ulong stack_ulong;
    51   Atomic_Pointer stack_ptr;
     53  Atomic_Uintptr stack_uintptr;
    5254  Atomic_Flag stack_flag;
    5355
     
    5658  _Atomic_Init_uint(&stack_uint, UINT_CONSTANT);
    5759  _Atomic_Init_ulong(&stack_ulong, 0xdeadbeefUL);
    58   _Atomic_Init_ptr(&stack_ptr, &static_ptr);
     60  _Atomic_Init_uintptr(&stack_uintptr, (uintptr_t) &static_uintptr);
    5961  _Atomic_Flag_clear(&stack_flag, ATOMIC_ORDER_RELAXED);
    6062
     
    6668  );
    6769  rtems_test_assert(
    68     memcmp(&stack_ptr, &static_ptr, sizeof(stack_ptr)) == 0
     70    memcmp(&stack_uintptr, &static_uintptr, sizeof(stack_uintptr)) == 0
    6971  );
    7072  rtems_test_assert(
     
    7981  );
    8082  rtems_test_assert(
    81     _Atomic_Load_ptr(&stack_ptr, ATOMIC_ORDER_RELAXED) == &static_ptr
     83    _Atomic_Load_uintptr(&stack_uintptr, ATOMIC_ORDER_RELAXED)
     84      == (uintptr_t) &static_uintptr
    8285  );
    8386  rtems_test_assert(
     
    9295  unsigned int ia = 8, ib = 4;
    9396  unsigned int ic;
     97  uintptr_t pa = 42, pb = 24;
     98  uintptr_t pc;
    9499  unsigned long a = 2, b = 1;
    95100  unsigned long c;
     
    97102  puts("=== atomic simple add test case ===");
    98103
    99   _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
    100   _Atomic_Fetch_add_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED);
    101   ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED);
     104  _Atomic_Store_uint(&ctx->uint_atomic, ia, ATOMIC_ORDER_RELAXED);
     105  _Atomic_Fetch_add_uint(&ctx->uint_atomic, ib, ATOMIC_ORDER_RELAXED);
     106  ic = _Atomic_Load_uint(&ctx->uint_atomic, ATOMIC_ORDER_RELAXED);
    102107  rtems_test_assert(ic == (ia + ib));
    103108
    104   _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
    105   _Atomic_Fetch_add_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED);
    106   c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     109  _Atomic_Store_uintptr(&ctx->uintptr_atomic, pa, ATOMIC_ORDER_RELAXED);
     110  _Atomic_Fetch_add_uintptr(&ctx->uintptr_atomic, pb, ATOMIC_ORDER_RELAXED);
     111  pc = _Atomic_Load_uintptr(&ctx->uintptr_atomic, ATOMIC_ORDER_RELAXED);
     112  rtems_test_assert(pc == (pa + pb));
     113
     114  _Atomic_Store_ulong(&ctx->ulong_atomic, a, ATOMIC_ORDER_RELAXED);
     115  _Atomic_Fetch_add_ulong(&ctx->ulong_atomic, b, ATOMIC_ORDER_RELAXED);
     116  c = _Atomic_Load_ulong(&ctx->ulong_atomic, ATOMIC_ORDER_RELAXED);
    107117  rtems_test_assert(c == (a + b));
    108118}
     
    112122  unsigned int ia = 8, ib = 4;
    113123  unsigned int ic;
     124  uintptr_t pa = 42, pb = 24;
     125  uintptr_t pc;
    114126  unsigned long a = 2, b = 1;
    115127  unsigned long c;
     
    117129  puts("=== atomic simple sub test case ===");
    118130
    119   _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
    120   _Atomic_Fetch_sub_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED);
    121   ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED);
     131  _Atomic_Store_uint(&ctx->uint_atomic, ia, ATOMIC_ORDER_RELAXED);
     132  _Atomic_Fetch_sub_uint(&ctx->uint_atomic, ib, ATOMIC_ORDER_RELAXED);
     133  ic = _Atomic_Load_uint(&ctx->uint_atomic, ATOMIC_ORDER_RELAXED);
    122134  rtems_test_assert(ic == (ia - ib));
    123135
    124   _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
    125   _Atomic_Fetch_sub_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED);
    126   c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     136  _Atomic_Store_uintptr(&ctx->uintptr_atomic, pa, ATOMIC_ORDER_RELAXED);
     137  _Atomic_Fetch_sub_uintptr(&ctx->uintptr_atomic, pb, ATOMIC_ORDER_RELAXED);
     138  pc = _Atomic_Load_uintptr(&ctx->uintptr_atomic, ATOMIC_ORDER_RELAXED);
     139  rtems_test_assert(pc == (pa - pb));
     140
     141  _Atomic_Store_ulong(&ctx->ulong_atomic, a, ATOMIC_ORDER_RELAXED);
     142  _Atomic_Fetch_sub_ulong(&ctx->ulong_atomic, b, ATOMIC_ORDER_RELAXED);
     143  c = _Atomic_Load_ulong(&ctx->ulong_atomic, ATOMIC_ORDER_RELAXED);
    127144  rtems_test_assert(c == (a - b));
    128145}
     
    132149  unsigned int ia = 8, ib = 4;
    133150  unsigned int ic;
     151  uintptr_t pa = 42, pb = 24;
     152  uintptr_t pc;
    134153  unsigned long a = 2, b = 1;
    135154  unsigned long c;
     
    137156  puts("=== atomic simple or test case ===");
    138157
    139   _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
    140   _Atomic_Fetch_or_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED);
    141   ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED);
     158  _Atomic_Store_uint(&ctx->uint_atomic, ia, ATOMIC_ORDER_RELAXED);
     159  _Atomic_Fetch_or_uint(&ctx->uint_atomic, ib, ATOMIC_ORDER_RELAXED);
     160  ic = _Atomic_Load_uint(&ctx->uint_atomic, ATOMIC_ORDER_RELAXED);
    142161  rtems_test_assert(ic == (ia | ib));
    143162
    144   _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
    145   _Atomic_Fetch_or_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED);
    146   c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     163  _Atomic_Store_uintptr(&ctx->uintptr_atomic, pa, ATOMIC_ORDER_RELAXED);
     164  _Atomic_Fetch_or_uintptr(&ctx->uintptr_atomic, pb, ATOMIC_ORDER_RELAXED);
     165  pc = _Atomic_Load_uintptr(&ctx->uintptr_atomic, ATOMIC_ORDER_RELAXED);
     166  rtems_test_assert(pc == (pa | pb));
     167
     168  _Atomic_Store_ulong(&ctx->ulong_atomic, a, ATOMIC_ORDER_RELAXED);
     169  _Atomic_Fetch_or_ulong(&ctx->ulong_atomic, b, ATOMIC_ORDER_RELAXED);
     170  c = _Atomic_Load_ulong(&ctx->ulong_atomic, ATOMIC_ORDER_RELAXED);
    147171  rtems_test_assert(c == (a | b));
    148172}
     
    152176  unsigned int ia = 8, ib = 4;
    153177  unsigned int ic;
     178  uintptr_t pa = 42, pb = 24;
     179  uintptr_t pc;
    154180  unsigned long a = 2, b = 1;
    155181  unsigned long c;
     
    157183  puts("=== atomic simple and test case ===");
    158184
    159   _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
    160   _Atomic_Fetch_and_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED);
    161   ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED);
     185  _Atomic_Store_uint(&ctx->uint_atomic, ia, ATOMIC_ORDER_RELAXED);
     186  _Atomic_Fetch_and_uint(&ctx->uint_atomic, ib, ATOMIC_ORDER_RELAXED);
     187  ic = _Atomic_Load_uint(&ctx->uint_atomic, ATOMIC_ORDER_RELAXED);
    162188  rtems_test_assert(ic == (ia & ib));
    163189
    164   _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
    165   _Atomic_Fetch_and_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED);
    166   c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     190  _Atomic_Store_uintptr(&ctx->uintptr_atomic, pa, ATOMIC_ORDER_RELAXED);
     191  _Atomic_Fetch_and_uintptr(&ctx->uintptr_atomic, pb, ATOMIC_ORDER_RELAXED);
     192  pc = _Atomic_Load_uintptr(&ctx->uintptr_atomic, ATOMIC_ORDER_RELAXED);
     193  rtems_test_assert(pc == (pa & pb));
     194
     195  _Atomic_Store_ulong(&ctx->ulong_atomic, a, ATOMIC_ORDER_RELAXED);
     196  _Atomic_Fetch_and_ulong(&ctx->ulong_atomic, b, ATOMIC_ORDER_RELAXED);
     197  c = _Atomic_Load_ulong(&ctx->ulong_atomic, ATOMIC_ORDER_RELAXED);
    167198  rtems_test_assert(c == (a & b));
    168199}
     
    172203  unsigned int ia = 8, ib = 4;
    173204  unsigned int ic;
     205  uintptr_t pa = 42, pb = 24;
     206  uintptr_t pc;
    174207  unsigned long a = 2, b = 1;
    175208  unsigned long c;
     
    177210  puts("=== atomic simple exchange test case ===");
    178211
    179   _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
    180   _Atomic_Exchange_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED);
    181   ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED);
     212  _Atomic_Store_uint(&ctx->uint_atomic, ia, ATOMIC_ORDER_RELAXED);
     213  ic = _Atomic_Exchange_uint(&ctx->uint_atomic, ib, ATOMIC_ORDER_RELAXED);
     214  rtems_test_assert(ic == ia);
     215  ic = _Atomic_Load_uint(&ctx->uint_atomic, ATOMIC_ORDER_RELAXED);
    182216  rtems_test_assert(ic == ib);
    183217
    184   _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
    185   _Atomic_Exchange_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED);
    186   c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     218  _Atomic_Store_uintptr(&ctx->uintptr_atomic, pa, ATOMIC_ORDER_RELAXED);
     219  pc = _Atomic_Exchange_uintptr(&ctx->uintptr_atomic, pb, ATOMIC_ORDER_RELAXED);
     220  rtems_test_assert(pc == pa);
     221  pc = _Atomic_Load_uintptr(&ctx->uintptr_atomic, ATOMIC_ORDER_RELAXED);
     222  rtems_test_assert(pc == pb);
     223
     224  _Atomic_Store_ulong(&ctx->ulong_atomic, a, ATOMIC_ORDER_RELAXED);
     225  c = _Atomic_Exchange_ulong(&ctx->ulong_atomic, b, ATOMIC_ORDER_RELAXED);
     226  rtems_test_assert(c == a);
     227  c = _Atomic_Load_ulong(&ctx->ulong_atomic, ATOMIC_ORDER_RELAXED);
    187228  rtems_test_assert(c == b);
    188229}
     
    192233  unsigned int ei;
    193234  unsigned int vi;
     235  uintptr_t ep;
     236  uintptr_t vp;
    194237  unsigned long el;
    195238  unsigned long vl;
     
    198241  puts("=== atomic simple compare exchange test case ===");
    199242
    200   _Atomic_Store_uint(&ctx->atomic_int_value, 1, ATOMIC_ORDER_RELAXED);
     243  _Atomic_Store_uint(&ctx->uint_atomic, 1, ATOMIC_ORDER_RELAXED);
    201244  ei = 2;
    202245  success = _Atomic_Compare_exchange_uint(
    203     &ctx->atomic_int_value,
     246    &ctx->uint_atomic,
    204247    &ei,
    205248    3,
     
    210253  rtems_test_assert(ei == 1);
    211254  success = _Atomic_Compare_exchange_uint(
    212     &ctx->atomic_int_value,
     255    &ctx->uint_atomic,
    213256    &ei,
    214257    3,
     
    217260  );
    218261  rtems_test_assert(success);
    219   vi = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED);
     262  vi = _Atomic_Load_uint(&ctx->uint_atomic, ATOMIC_ORDER_RELAXED);
    220263  rtems_test_assert(vi == 3);
    221264
    222   _Atomic_Store_ulong(&ctx->atomic_value, 10, ATOMIC_ORDER_RELAXED);
     265  _Atomic_Store_uintptr(&ctx->uintptr_atomic, 111, ATOMIC_ORDER_RELAXED);
     266  ep = 211;
     267  success = _Atomic_Compare_exchange_uintptr(
     268    &ctx->uintptr_atomic,
     269    &ep,
     270    311,
     271    ATOMIC_ORDER_RELAXED,
     272    ATOMIC_ORDER_RELAXED
     273  );
     274  rtems_test_assert(!success);
     275  rtems_test_assert(ep == 111);
     276  success = _Atomic_Compare_exchange_uintptr(
     277    &ctx->uintptr_atomic,
     278    &ep,
     279    311,
     280    ATOMIC_ORDER_RELAXED,
     281    ATOMIC_ORDER_RELAXED
     282  );
     283  rtems_test_assert(success);
     284  vp = _Atomic_Load_uintptr(&ctx->uintptr_atomic, ATOMIC_ORDER_RELAXED);
     285  rtems_test_assert(vp == 311);
     286
     287  _Atomic_Store_ulong(&ctx->ulong_atomic, 10, ATOMIC_ORDER_RELAXED);
    223288  el = 11;
    224289  success = _Atomic_Compare_exchange_ulong(
    225     &ctx->atomic_value,
     290    &ctx->ulong_atomic,
    226291    &el,
    227292    12,
     
    232297  rtems_test_assert(el == 10);
    233298  success = _Atomic_Compare_exchange_ulong(
    234     &ctx->atomic_value,
     299    &ctx->ulong_atomic,
    235300    &el,
    236301    12,
     
    239304  );
    240305  rtems_test_assert(success);
    241   vl = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     306  vl = _Atomic_Load_ulong(&ctx->ulong_atomic, ATOMIC_ORDER_RELAXED);
    242307  rtems_test_assert(vl == 12);
    243308}
Note: See TracChangeset for help on using the changeset viewer.