Changeset 4621d23 in mainline for kernel/generic/include/atomic.h
- Timestamp:
- 2018-09-06T19:54:11Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 508b0df1
- Parents:
- ffa73c6
- git-author:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-08-13 03:00:17)
- git-committer:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-09-06 19:54:11)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/atomic.h
rffa73c6 r4621d23 36 36 #define KERN_ATOMIC_H_ 37 37 38 #include <stdbool.h> 38 39 #include <typedefs.h> 39 #include <arch/atomic.h> 40 #include <verify.h> 40 #include <stdatomic.h> 41 41 42 NO_TRACE ATOMIC static inline void atomic_set(atomic_t *val, atomic_count_t i) 43 WRITES(&val->count) 44 REQUIRES_EXTENT_MUTABLE(val) 42 typedef size_t atomic_count_t; 43 typedef ssize_t atomic_signed_t; 44 45 #define PRIua "zu" /**< Format for atomic_count_t. */ 46 47 typedef struct { 48 volatile atomic_size_t count; 49 } atomic_t; 50 51 static inline void atomic_set(atomic_t *val, atomic_count_t i) 45 52 { 46 val->count = i;53 atomic_store(&val->count, i); 47 54 } 48 55 49 NO_TRACE ATOMIC static inline atomic_count_t atomic_get(atomic_t *val) 50 REQUIRES_EXTENT_MUTABLE(val) 56 static inline atomic_count_t atomic_get(atomic_t *val) 51 57 { 52 return val->count;58 return atomic_load(&val->count); 53 59 } 54 60 61 static inline size_t atomic_predec(atomic_t *val) 62 { 63 return atomic_fetch_sub(&val->count, 1) - 1; 64 } 55 65 56 /* 57 * If the architecture does not provide operations that are atomic 58 * only with respect to the local cpu (eg exception handlers) and 59 * not other cpus, implement these cpu local atomic operations with 60 * full blown smp-safe atomics. 61 */ 62 #ifndef local_atomic_exchange 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 } 90 63 91 #define local_atomic_exchange(var_addr, new_val) \ 64 __atomic_exchange_n((var_addr), (new_val), __ATOMIC_RELAXED) 65 #endif 92 atomic_exchange_explicit(var_addr, new_val, memory_order_relaxed) 66 93 94 static inline bool test_and_set(atomic_t *val) 95 { 96 return atomic_exchange(&val->count, 1); 97 } 67 98 68 99
Note:
See TracChangeset
for help on using the changeset viewer.