1 #ifndef _TOOLS_LINUX_ASM_X86_ATOMIC_H
2 #define _TOOLS_LINUX_ASM_X86_ATOMIC_H
4 #include <linux/compiler.h>
5 #include <linux/types.h>
8 #define LOCK_PREFIX "\n\tlock; "
11 * Atomic operations that C can't guarantee us. Useful for
12 * resource counting etc..
15 #define ATOMIC_INIT(i) { (i) }
18 * atomic_read - read atomic variable
19 * @v: pointer of type atomic_t
21 * Atomically reads the value of @v.
23 static inline int atomic_read(const atomic_t *v)
25 return ACCESS_ONCE((v)->counter);
29 * atomic_set - set atomic variable
30 * @v: pointer of type atomic_t
33 * Atomically sets the value of @v to @i.
35 static inline void atomic_set(atomic_t *v, int i)
41 * atomic_inc - increment atomic variable
42 * @v: pointer of type atomic_t
44 * Atomically increments @v by 1.
46 static inline void atomic_inc(atomic_t *v)
48 asm volatile(LOCK_PREFIX "incl %0"
53 * atomic_dec_and_test - decrement and test
54 * @v: pointer of type atomic_t
56 * Atomically decrements @v by 1 and
57 * returns true if the result is 0, or false for all other
60 static inline int atomic_dec_and_test(atomic_t *v)
62 GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
65 #endif /* _TOOLS_LINUX_ASM_X86_ATOMIC_H */