Changeset ffa73c6 in mainline for uspace/lib/c/include
- Timestamp:
- 2018-09-06T18:49:14Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4621d23
- Parents:
- 7328ff4
- git-author:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-08-13 02:26:04)
- git-committer:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-09-06 18:49:14)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/atomic.h
r7328ff4 rffa73c6 36 36 #define LIBC_ATOMIC_H_ 37 37 38 #include <libarch/atomic.h> 38 #include <stdatomic.h> 39 #include <stdbool.h> 40 #include <stddef.h> 41 42 typedef size_t atomic_count_t; 43 typedef ssize_t atomic_signed_t; 44 45 typedef struct atomic { 46 volatile atomic_size_t count; 47 } atomic_t; 48 49 static inline void atomic_set(atomic_t *val, atomic_count_t i) 50 { 51 atomic_store(&val->count, i); 52 } 53 54 static inline atomic_count_t atomic_get(atomic_t *val) 55 { 56 return atomic_load(&val->count); 57 } 58 59 static inline bool cas(atomic_t *val, atomic_count_t ov, atomic_count_t nv) 60 { 61 return atomic_compare_exchange_strong(&val->count, &ov, nv); 62 } 63 64 static inline atomic_count_t atomic_postinc(atomic_t *val) 65 { 66 return atomic_fetch_add(&val->count, 1); 67 } 68 69 static inline atomic_count_t atomic_postdec(atomic_t *val) 70 { 71 return atomic_fetch_sub(&val->count, 1); 72 } 73 74 static inline atomic_count_t atomic_preinc(atomic_t *val) 75 { 76 return atomic_postinc(val) + 1; 77 } 78 79 static inline atomic_count_t atomic_predec(atomic_t *val) 80 { 81 return atomic_postdec(val) - 1; 82 } 83 84 static inline void atomic_inc(atomic_t *val) 85 { 86 atomic_postinc(val); 87 } 88 89 static inline void atomic_dec(atomic_t *val) 90 { 91 atomic_postdec(val); 92 } 39 93 40 94 #endif
Note:
See TracChangeset
for help on using the changeset viewer.