1 #ifndef _ASM_X86_ATOMIC64_32_H
2 #define _ASM_X86_ATOMIC64_32_H
4 #include <linux/compiler.h>
5 #include <linux/types.h>
6 #include <asm/processor.h>
7 //#include <asm/cmpxchg.h>
9 /* An 64bit atomic type */
12 u64 __aligned(8) counter;
15 #define ATOMIC64_INIT(val) { (val) }
17 extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val);
20 * atomic64_xchg - xchg atomic64 variable
21 * @ptr: pointer to type atomic64_t
22 * @new_val: value to assign
24 * Atomically xchgs the value of @ptr to @new_val and returns
27 extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val);
30 * atomic64_set - set atomic64 variable
31 * @ptr: pointer to type atomic64_t
32 * @new_val: value to assign
34 * Atomically sets the value of @ptr to @new_val.
36 extern void atomic64_set(atomic64_t *ptr, u64 new_val);
39 * atomic64_read - read atomic64 variable
40 * @ptr: pointer to type atomic64_t
42 * Atomically reads the value of @ptr and returns it.
44 static inline u64 atomic64_read(atomic64_t *ptr)
49 * Note, we inline this atomic64_t primitive because
50 * it only clobbers EAX/EDX and leaves the others
51 * untouched. We also (somewhat subtly) rely on the
52 * fact that cmpxchg8b returns the current 64-bit value
53 * of the memory location we are touching:
56 "mov %%ebx, %%eax\n\t"
57 "mov %%ecx, %%edx\n\t"
58 LOCK_PREFIX "cmpxchg8b %1\n"
66 extern u64 atomic64_read(atomic64_t *ptr);
69 * atomic64_add_return - add and return
70 * @delta: integer value to add
71 * @ptr: pointer to type atomic64_t
73 * Atomically adds @delta to @ptr and returns @delta + *@ptr
75 extern u64 atomic64_add_return(u64 delta, atomic64_t *ptr);
78 * Other variants with different arithmetic operators:
80 extern u64 atomic64_sub_return(u64 delta, atomic64_t *ptr);
81 extern u64 atomic64_inc_return(atomic64_t *ptr);
82 extern u64 atomic64_dec_return(atomic64_t *ptr);
85 * atomic64_add - add integer to atomic64 variable
86 * @delta: integer value to add
87 * @ptr: pointer to type atomic64_t
89 * Atomically adds @delta to @ptr.
91 extern void atomic64_add(u64 delta, atomic64_t *ptr);
94 * atomic64_sub - subtract the atomic64 variable
95 * @delta: integer value to subtract
96 * @ptr: pointer to type atomic64_t
98 * Atomically subtracts @delta from @ptr.
100 extern void atomic64_sub(u64 delta, atomic64_t *ptr);
103 * atomic64_sub_and_test - subtract value from variable and test result
104 * @delta: integer value to subtract
105 * @ptr: pointer to type atomic64_t
107 * Atomically subtracts @delta from @ptr and returns
108 * true if the result is zero, or false for all
111 extern int atomic64_sub_and_test(u64 delta, atomic64_t *ptr);
114 * atomic64_inc - increment atomic64 variable
115 * @ptr: pointer to type atomic64_t
117 * Atomically increments @ptr by 1.
119 extern void atomic64_inc(atomic64_t *ptr);
122 * atomic64_dec - decrement atomic64 variable
123 * @ptr: pointer to type atomic64_t
125 * Atomically decrements @ptr by 1.
127 extern void atomic64_dec(atomic64_t *ptr);
130 * atomic64_dec_and_test - decrement and test
131 * @ptr: pointer to type atomic64_t
133 * Atomically decrements @ptr by 1 and
134 * returns true if the result is 0, or false for all other
137 extern int atomic64_dec_and_test(atomic64_t *ptr);
140 * atomic64_inc_and_test - increment and test
141 * @ptr: pointer to type atomic64_t
143 * Atomically increments @ptr by 1
144 * and returns true if the result is zero, or false for all
147 extern int atomic64_inc_and_test(atomic64_t *ptr);
150 * atomic64_add_negative - add and test if negative
151 * @delta: integer value to add
152 * @ptr: pointer to type atomic64_t
154 * Atomically adds @delta to @ptr and returns true
155 * if the result is negative, or false when
156 * result is greater than or equal to zero.
158 extern int atomic64_add_negative(u64 delta, atomic64_t *ptr);
160 #endif /* _ASM_X86_ATOMIC64_32_H */