Changes in kernel/generic/include/atomic.h [c53e813:4621d23] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/atomic.h
rc53e813 r4621d23 40 40 #include <stdatomic.h> 41 41 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. 49 typedef atomic_size_t atomic_t; 42 typedef size_t atomic_count_t; 43 typedef ssize_t atomic_signed_t; 50 44 51 #define atomic_predec(val) \ 52 (atomic_fetch_sub((val), 1) - 1) 45 #define PRIua "zu" /**< Format for atomic_count_t. */ 53 46 54 #define atomic_preinc(val) \ 55 (atomic_fetch_add((val), 1) + 1) 47 typedef struct { 48 volatile atomic_size_t count; 49 } atomic_t; 56 50 57 #define atomic_postdec(val) \ 58 atomic_fetch_sub((val), 1) 51 static inline void atomic_set(atomic_t *val, atomic_count_t i) 52 { 53 atomic_store(&val->count, i); 54 } 59 55 60 #define atomic_postinc(val) \ 61 atomic_fetch_add((val), 1) 56 static inline atomic_count_t atomic_get(atomic_t *val) 57 { 58 return atomic_load(&val->count); 59 } 62 60 63 #define atomic_dec(val) \ 64 ((void) atomic_fetch_sub(val, 1)) 61 static inline size_t atomic_predec(atomic_t *val) 62 { 63 return atomic_fetch_sub(&val->count, 1) - 1; 64 } 65 65 66 #define atomic_inc(val) \ 67 ((void) atomic_fetch_add(val, 1)) 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 } 68 90 69 91 #define local_atomic_exchange(var_addr, new_val) \ 70 92 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 71 99 72 100 #endif
Note:
See TracChangeset
for help on using the changeset viewer.