0001
0002 #ifndef __TOOLS_ASM_GENERIC_ATOMIC_H
0003 #define __TOOLS_ASM_GENERIC_ATOMIC_H
0004
0005 #include <linux/compiler.h>
0006 #include <linux/types.h>
0007
0008
0009
0010
0011
0012
0013
0014
0015 #define ATOMIC_INIT(i) { (i) }
0016
0017
0018
0019
0020
0021
0022
0023 static inline int atomic_read(const atomic_t *v)
0024 {
0025 return READ_ONCE((v)->counter);
0026 }
0027
0028
0029
0030
0031
0032
0033
0034
0035 static inline void atomic_set(atomic_t *v, int i)
0036 {
0037 v->counter = i;
0038 }
0039
0040
0041
0042
0043
0044
0045
0046 static inline void atomic_inc(atomic_t *v)
0047 {
0048 __sync_add_and_fetch(&v->counter, 1);
0049 }
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 static inline int atomic_dec_and_test(atomic_t *v)
0060 {
0061 return __sync_sub_and_fetch(&v->counter, 1) == 0;
0062 }
0063
0064 #define cmpxchg(ptr, oldval, newval) \
0065 __sync_val_compare_and_swap(ptr, oldval, newval)
0066
0067 static inline int atomic_cmpxchg(atomic_t *v, int oldval, int newval)
0068 {
0069 return cmpxchg(&(v)->counter, oldval, newval);
0070 }
0071
0072 #endif