Changeset c53e813 in mainline for kernel/generic/include/atomic.h


Ignore:
Timestamp:
2018-09-07T16:18:10Z (6 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e90cfa6
Parents:
3cfe2b8
Message:

Change atomic increment/decrement routines to type-generic macros

<stdatomic.h> is type-generic by design, so we don't need to restrict
ourselves to a particular type.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/atomic.h

    r3cfe2b8 rc53e813  
    4040#include <stdatomic.h>
    4141
     42// TODO: Remove.
     43// Before <stdatomic.h> was available, there was only one atomic type
     44// equivalent to atomic_size_t. This means that in some places, atomic_t can
     45// be replaced with a more appropriate type (e.g. atomic_bool for flags or
     46// a signed type for potentially signed values).
     47// So atomic_t should be replaced with the most appropriate type on a case by
     48// case basis, and after there are no more uses, remove this type.
    4249typedef atomic_size_t atomic_t;
    4350
    44 static inline size_t atomic_predec(atomic_t *val)
    45 {
    46         return atomic_fetch_sub(val, 1) - 1;
    47 }
     51#define atomic_predec(val) \
     52        (atomic_fetch_sub((val), 1) - 1)
    4853
    49 static inline size_t atomic_preinc(atomic_t *val)
    50 {
    51         return atomic_fetch_add(val, 1) + 1;
    52 }
     54#define atomic_preinc(val) \
     55        (atomic_fetch_add((val), 1) + 1)
    5356
    54 static inline size_t atomic_postdec(atomic_t *val)
    55 {
    56         return atomic_fetch_sub(val, 1);
    57 }
     57#define atomic_postdec(val) \
     58        atomic_fetch_sub((val), 1)
    5859
    59 static inline size_t atomic_postinc(atomic_t *val)
    60 {
    61         return atomic_fetch_add(val, 1);
    62 }
     60#define atomic_postinc(val) \
     61        atomic_fetch_add((val), 1)
    6362
    64 static inline void atomic_dec(atomic_t *val)
    65 {
    66         atomic_fetch_sub(val, 1);
    67 }
     63#define atomic_dec(val) \
     64        ((void) atomic_fetch_sub(val, 1))
    6865
    69 static inline void atomic_inc(atomic_t *val)
    70 {
    71         atomic_fetch_add(val, 1);
    72 }
     66#define atomic_inc(val) \
     67        ((void) atomic_fetch_add(val, 1))
    7368
    7469#define local_atomic_exchange(var_addr, new_val) \
Note: See TracChangeset for help on using the changeset viewer.