Ignore:
File:
1 edited

Legend:

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

    r4621d23 rc53e813  
    4040#include <stdatomic.h>
    4141
    42 typedef size_t atomic_count_t;
    43 typedef ssize_t atomic_signed_t;
     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.
     49typedef atomic_size_t atomic_t;
    4450
    45 #define PRIua  "zu"          /**< Format for atomic_count_t. */
     51#define atomic_predec(val) \
     52        (atomic_fetch_sub((val), 1) - 1)
    4653
    47 typedef struct {
    48         volatile atomic_size_t count;
    49 } atomic_t;
     54#define atomic_preinc(val) \
     55        (atomic_fetch_add((val), 1) + 1)
    5056
    51 static inline void atomic_set(atomic_t *val, atomic_count_t i)
    52 {
    53         atomic_store(&val->count, i);
    54 }
     57#define atomic_postdec(val) \
     58        atomic_fetch_sub((val), 1)
    5559
    56 static inline atomic_count_t atomic_get(atomic_t *val)
    57 {
    58         return atomic_load(&val->count);
    59 }
     60#define atomic_postinc(val) \
     61        atomic_fetch_add((val), 1)
    6062
    61 static inline size_t atomic_predec(atomic_t *val)
    62 {
    63         return atomic_fetch_sub(&val->count, 1) - 1;
    64 }
     63#define atomic_dec(val) \
     64        ((void) atomic_fetch_sub(val, 1))
    6565
    66 static inline size_t atomic_preinc(atomic_t *val)
    67 {
    68         return atomic_fetch_add(&val->count, 1) + 1;
    69 }
    70 
    71 static inline size_t atomic_postdec(atomic_t *val)
    72 {
    73         return atomic_fetch_sub(&val->count, 1);
    74 }
    75 
    76 static inline size_t atomic_postinc(atomic_t *val)
    77 {
    78         return atomic_fetch_add(&val->count, 1);
    79 }
    80 
    81 static inline void atomic_dec(atomic_t *val)
    82 {
    83         atomic_fetch_sub(&val->count, 1);
    84 }
    85 
    86 static inline void atomic_inc(atomic_t *val)
    87 {
    88         atomic_fetch_add(&val->count, 1);
    89 }
     66#define atomic_inc(val) \
     67        ((void) atomic_fetch_add(val, 1))
    9068
    9169#define local_atomic_exchange(var_addr, new_val) \
    9270        atomic_exchange_explicit(var_addr, new_val, memory_order_relaxed)
    93 
    94 static inline bool test_and_set(atomic_t *val)
    95 {
    96         return atomic_exchange(&val->count, 1);
    97 }
    98 
    9971
    10072#endif
Note: See TracChangeset for help on using the changeset viewer.