Changeset 945853b7 in rtems


Ignore:
Timestamp:
Feb 13, 2014, 2:38:52 PM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
ad56361
Parents:
cd2c655
git-author:
Sebastian Huber <sebastian.huber@…> (02/13/14 14:38:52)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/14/14 09:28:30)
Message:

score: Add Atomic_Uint

Files:
3 edited

Legend:

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

    rcd2c655 r945853b7  
    3535 * @brief atomic data initializer for static initialization.
    3636 */
     37#define ATOMIC_INITIALIZER_UINT(value) CPU_ATOMIC_INITIALIZER_UINT(value)
    3738#define ATOMIC_INITIALIZER_ULONG(value) CPU_ATOMIC_INITIALIZER_ULONG(value)
    3839#define ATOMIC_INITIALIZER_PTR(value) CPU_ATOMIC_INITIALIZER_PTR(value)
     
    4950 * @param pointer a pointer to be stored into object.
    5051 */
     52static inline void _Atomic_Init_uint(
     53  volatile Atomic_Uint *object,
     54  unsigned int value
     55)
     56{
     57  _CPU_atomic_Init_uint(object, value);
     58}
     59
    5160static inline void _Atomic_Init_ulong(
    5261  volatile Atomic_Ulong *object,
     
    7382 * The order shall not be ATOMIC_ORDER_RELEASE.
    7483 */
     84static inline unsigned int _Atomic_Load_uint(
     85  volatile Atomic_Uint *object,
     86  Atomic_Order order
     87)
     88{
     89  return _CPU_atomic_Load_uint( object, order );
     90}
     91
    7592static inline unsigned long _Atomic_Load_ulong(
    7693  volatile Atomic_Ulong *object,
     
    98115 * The order shall not be ATOMIC_ORDER_ACQUIRE.
    99116 */
     117static inline void _Atomic_Store_uint(
     118  volatile Atomic_Uint *object,
     119  unsigned int value,
     120  Atomic_Order order
     121)
     122{
     123  _CPU_atomic_Store_uint( object, value, order );
     124}
     125
    100126static inline void _Atomic_Store_ulong(
    101127  volatile Atomic_Ulong *object,
     
    125151 * @retval a result value before add ops.
    126152 */
     153static inline unsigned int _Atomic_Fetch_add_uint(
     154  volatile Atomic_Uint *object,
     155  unsigned int value,
     156  Atomic_Order order
     157)
     158{
     159  return _CPU_atomic_Fetch_add_uint( object, value, order );
     160}
     161
    127162static inline unsigned long _Atomic_Fetch_add_ulong(
    128163  volatile Atomic_Ulong *object,
     
    152187 * @retval a result value before sub ops.
    153188 */
     189static inline unsigned int _Atomic_Fetch_sub_uint(
     190  volatile Atomic_Uint *object,
     191  unsigned int value,
     192  Atomic_Order order
     193)
     194{
     195  return _CPU_atomic_Fetch_sub_uint( object, value, order );
     196}
     197
    154198static inline unsigned long _Atomic_Fetch_sub_ulong(
    155199  volatile Atomic_Ulong *object,
     
    179223 * @retval a result value before or ops.
    180224 */
     225static inline unsigned int _Atomic_Fetch_or_uint(
     226  volatile Atomic_Uint *object,
     227  unsigned int value,
     228  Atomic_Order order
     229)
     230{
     231  return _CPU_atomic_Fetch_or_uint( object, value, order );
     232}
     233
    181234static inline unsigned long _Atomic_Fetch_or_ulong(
    182235  volatile Atomic_Ulong *object,
     
    206259 * @retval a result value before and ops.
    207260 */
     261static inline unsigned int _Atomic_Fetch_and_uint(
     262  volatile Atomic_Uint *object,
     263  unsigned int value,
     264  Atomic_Order order
     265)
     266{
     267  return _CPU_atomic_Fetch_and_uint( object, value, order );
     268}
     269
    208270static inline unsigned long _Atomic_Fetch_and_ulong(
    209271  volatile Atomic_Ulong *object,
     
    233295 * @retval a result value before exchange ops.
    234296 */
     297static inline unsigned int _Atomic_Exchange_uint(
     298 volatile Atomic_Uint *object,
     299 unsigned int value,
     300 Atomic_Order order
     301)
     302{
     303  return _CPU_atomic_Exchange_uint( object, value, order );
     304}
     305
    235306static inline unsigned long _Atomic_Exchange_ulong(
    236307 volatile Atomic_Ulong *object,
     
    265336 * @retval false if the compare exchange failed.
    266337 */
     338static inline bool _Atomic_Compare_exchange_uint(
     339  volatile Atomic_Uint *object,
     340  unsigned int *old_value,
     341  unsigned int new_value,
     342  Atomic_Order order_succ,
     343  Atomic_Order order_fail
     344)
     345{
     346  return _CPU_atomic_Compare_exchange_uint( object, old_value, new_value,
     347    order_succ, order_fail );
     348}
     349
    267350static inline bool _Atomic_Compare_exchange_ulong(
    268351  volatile Atomic_Ulong *object,
  • cpukit/score/include/rtems/score/cpustdatomic.h

    rcd2c655 r945853b7  
    3535/**
    3636 * @brief atomic operation unsigned integer type
     37 */
     38typedef atomic_uint Atomic_Uint;
     39
     40/**
     41 * @brief atomic operation unsigned long integer type
    3742 */
    3843typedef atomic_ulong Atomic_Ulong;
     
    7277 * @brief atomic data initializer for static initialization.
    7378 */
     79#define CPU_ATOMIC_INITIALIZER_UINT(value) ATOMIC_VAR_INIT(value)
    7480#define CPU_ATOMIC_INITIALIZER_ULONG(value) ATOMIC_VAR_INIT(value)
    7581#define CPU_ATOMIC_INITIALIZER_PTR(pointer) \
     
    8490 * @param value a value to be stored into object.
    8591 */
     92static inline void _CPU_atomic_Init_uint(
     93  volatile Atomic_Uint *object,
     94  unsigned int value
     95)
     96{
     97  atomic_init( object, value );
     98}
     99
    86100static inline void _CPU_atomic_Init_ulong(
    87101  volatile Atomic_Ulong *object,
     
    108122 * The order shall not be ATOMIC_ORDER_RELEASE.
    109123 */
     124static inline unsigned int _CPU_atomic_Load_uint(
     125  volatile Atomic_Uint *object,
     126  Atomic_Order order
     127)
     128{
     129  return atomic_load_explicit( object, (memory_order) order );
     130}
     131
    110132static inline unsigned long _CPU_atomic_Load_ulong(
    111133  volatile Atomic_Ulong *object,
     
    133155 * The order shall not be ATOMIC_ORDER_ACQUIRE.
    134156 */
     157static inline void _CPU_atomic_Store_uint(
     158  volatile Atomic_Uint *object,
     159  unsigned int value,
     160  Atomic_Order order
     161)
     162{
     163  atomic_store_explicit( object, value, (memory_order) order );
     164}
     165
    135166static inline void _CPU_atomic_Store_ulong(
    136167  volatile Atomic_Ulong *object,
     
    160191 * @retval a result value before add ops.
    161192 */
     193static inline unsigned int _CPU_atomic_Fetch_add_uint(
     194  volatile Atomic_Uint *object,
     195  unsigned int value,
     196  Atomic_Order order
     197)
     198{
     199  return atomic_fetch_add_explicit( object, value, (memory_order) order );
     200}
     201
    162202static inline unsigned long _CPU_atomic_Fetch_add_ulong(
    163203  volatile Atomic_Ulong *object,
     
    187227 * @retval a result value before sub ops.
    188228 */
     229static inline unsigned int _CPU_atomic_Fetch_sub_uint(
     230  volatile Atomic_Uint *object,
     231  unsigned int value,
     232  Atomic_Order order
     233)
     234{
     235  return atomic_fetch_sub_explicit( object, value, (memory_order) order );
     236}
     237
    189238static inline unsigned long _CPU_atomic_Fetch_sub_ulong(
    190239  volatile Atomic_Ulong *object,
     
    214263 * @retval a result value before or ops.
    215264 */
     265static inline unsigned int _CPU_atomic_Fetch_or_uint(
     266  volatile Atomic_Uint *object,
     267  unsigned int value,
     268  Atomic_Order order
     269)
     270{
     271  return atomic_fetch_or_explicit( object, value, (memory_order) order );
     272}
     273
    216274static inline unsigned long _CPU_atomic_Fetch_or_ulong(
    217275  volatile Atomic_Ulong *object,
     
    241299 * @retval a result value before and ops.
    242300 */
     301static inline unsigned int _CPU_atomic_Fetch_and_uint(
     302  volatile Atomic_Uint *object,
     303  unsigned int value,
     304  Atomic_Order order
     305)
     306{
     307  return atomic_fetch_and_explicit( object, value, (memory_order) order );
     308}
     309
    243310static inline unsigned long _CPU_atomic_Fetch_and_ulong(
    244311  volatile Atomic_Ulong *object,
     
    268335 * @retval a result value before exchange ops.
    269336 */
     337static inline unsigned int _CPU_atomic_Exchange_uint(
     338 volatile Atomic_Uint *object,
     339 unsigned int value,
     340 Atomic_Order order
     341)
     342{
     343  return atomic_exchange_explicit( object, value, (memory_order) order );
     344}
     345
    270346static inline unsigned long _CPU_atomic_Exchange_ulong(
    271347 volatile Atomic_Ulong *object,
     
    304380 * @retval false if the compare exchange failed.
    305381 */
     382static inline bool _CPU_atomic_Compare_exchange_uint(
     383  volatile Atomic_Uint *object,
     384  unsigned int *old_value,
     385  unsigned int new_value,
     386  Atomic_Order order_succ,
     387  Atomic_Order order_fail
     388)
     389{
     390  return atomic_compare_exchange_strong_explicit( object, old_value,
     391    new_value, order_succ, order_fail );
     392}
     393
    306394static inline bool _CPU_atomic_Compare_exchange_ulong(
    307395  volatile Atomic_Ulong *object,
  • testsuites/smptests/smpatomic01/init.c

    rcd2c655 r945853b7  
    8181  size_t worker_count;
    8282  rtems_id stop_worker_timer_id;
     83  Atomic_Uint atomic_int_value;
    8384  Atomic_Ulong atomic_value;
    8485  unsigned long per_worker_value[CPU_COUNT];
     
    384385static void test_static_and_dynamic_initialization(void)
    385386{
     387  static Atomic_Uint static_uint =
     388    ATOMIC_INITIALIZER_UINT(0xc01dc0feU);
    386389  static Atomic_Ulong static_ulong =
    387390    ATOMIC_INITIALIZER_ULONG(0xdeadbeefUL);
     
    390393  static Atomic_Flag static_flag = ATOMIC_INITIALIZER_FLAG;
    391394
     395  Atomic_Uint stack_uint;
    392396  Atomic_Ulong stack_ulong;
    393397  Atomic_Pointer stack_ptr;
     
    396400  puts("=== static and dynamic initialization test case ===");
    397401
     402  _Atomic_Init_uint(&stack_uint, 0xc01dc0feU);
    398403  _Atomic_Init_ulong(&stack_ulong, 0xdeadbeefUL);
    399404  _Atomic_Init_ptr(&stack_ptr, &static_ptr);
     
    401406
    402407  rtems_test_assert(
     408    memcmp(&stack_uint, &static_uint, sizeof(stack_uint)) == 0
     409  );
     410  rtems_test_assert(
    403411    memcmp(&stack_ulong, &static_ulong, sizeof(stack_ulong)) == 0
    404412  );
     
    410418  );
    411419
     420  rtems_test_assert(
     421    _Atomic_Load_uint(&stack_uint, ATOMIC_ORDER_RELAXED) == 0xc01dc0feU
     422  );
    412423  rtems_test_assert(
    413424    _Atomic_Load_ulong(&stack_ulong, ATOMIC_ORDER_RELAXED) == 0xdeadbeefUL
     
    461472static void test_simple_atomic_add_body(test_context *ctx)
    462473{
     474  unsigned int ia = 8, ib = 4;
     475  unsigned int ic;
    463476  unsigned long a = 2, b = 1;
    464477  unsigned long c;
    465478
    466479  puts("=== atomic simple add test case ==\n");
     480
     481  _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
     482  _Atomic_Fetch_add_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED);
     483  ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED);
     484  rtems_test_assert(ic == (ia + ib));
    467485
    468486  _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
     
    474492static void test_simple_atomic_sub_body(test_context *ctx)
    475493{
     494  unsigned int ia = 8, ib = 4;
     495  unsigned int ic;
    476496  unsigned long a = 2, b = 1;
    477497  unsigned long c;
    478498
    479499  puts("=== atomic simple sub test case ==\n");
     500
     501  _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
     502  _Atomic_Fetch_sub_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED);
     503  ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED);
     504  rtems_test_assert(ic == (ia - ib));
    480505
    481506  _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
     
    487512static void test_simple_atomic_or_body(test_context *ctx)
    488513{
     514  unsigned int ia = 8, ib = 4;
     515  unsigned int ic;
    489516  unsigned long a = 2, b = 1;
    490517  unsigned long c;
    491518
    492519  puts("=== atomic simple or test case ==\n");
     520
     521  _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
     522  _Atomic_Fetch_or_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED);
     523  ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED);
     524  rtems_test_assert(ic == (ia | ib));
    493525
    494526  _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
     
    500532static void test_simple_atomic_and_body(test_context *ctx)
    501533{
     534  unsigned int ia = 8, ib = 4;
     535  unsigned int ic;
    502536  unsigned long a = 2, b = 1;
    503537  unsigned long c;
    504538
    505539  puts("=== atomic simple and test case ==\n");
     540
     541  _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
     542  _Atomic_Fetch_and_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED);
     543  ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED);
     544  rtems_test_assert(ic == (ia & ib));
    506545
    507546  _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
     
    513552static void test_simple_atomic_exchange_body(test_context *ctx)
    514553{
     554  unsigned int ia = 8, ib = 4;
     555  unsigned int ic;
    515556  unsigned long a = 2, b = 1;
    516557  unsigned long c;
    517558
    518559  puts("=== atomic simple exchange test case ==\n");
     560
     561  _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
     562  _Atomic_Exchange_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED);
     563  ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED);
     564  rtems_test_assert(ic == ib);
    519565
    520566  _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
     
    526572static void test_simple_atomic_compare_exchange_body(test_context *ctx)
    527573{
     574  unsigned int ia = 8, ib = 4;
     575  unsigned int ic;
    528576  unsigned long a = 2, b = 1;
    529577  unsigned long c;
    530578
    531579  puts("=== atomic simple compare exchange test case ==\n");
     580
     581  _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
     582  _Atomic_Compare_exchange_uint(&ctx->atomic_int_value, &ia, ib,
     583    ATOMIC_ORDER_RELAXED, ATOMIC_ORDER_RELAXED);
     584  ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED);
     585  rtems_test_assert(ic == ib);
    532586
    533587  _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
Note: See TracChangeset for help on using the changeset viewer.