1 #ifndef _ASM_X86_ATOMIC_H
2 #define _ASM_X86_ATOMIC_H
4 #include <linux/bitops.h>
5 #include <linux/compiler.h>
6 #include <linux/types.h>
7 #include <asm/processor.h>
9 typedef struct { volatile int counter; } atomic_t;
12 * Atomic operations that C can't guarantee us. Useful for
13 * resource counting etc..
16 #define ATOMIC_INIT(i) { (i) }
19 * atomic_read - read atomic variable
20 * @v: pointer of type atomic_t
22 * Atomically reads the value of @v.
24 static inline int atomic_read(const atomic_t *v)
26 return ACCESS_ONCE((v)->counter);
30 * atomic_set - set atomic variable
31 * @v: pointer of type atomic_t
34 * Atomically sets the value of @v to @i.
36 static inline void atomic_set(atomic_t *v, int i)
42 * atomic_add - add integer to atomic variable
43 * @i: integer value to add
44 * @v: pointer of type atomic_t
46 * Atomically adds @i to @v.
48 static inline void atomic_add(int i, atomic_t *v)
50 asm volatile(LOCK_PREFIX "addl %1,%0"
56 * atomic_sub - subtract integer from atomic variable
57 * @i: integer value to subtract
58 * @v: pointer of type atomic_t
60 * Atomically subtracts @i from @v.
62 static inline void atomic_sub(int i, atomic_t *v)
64 asm volatile(LOCK_PREFIX "subl %1,%0"
70 * atomic_inc - increment atomic variable
71 * @v: pointer of type atomic_t
73 * Atomically increments @v by 1.
75 static inline void atomic_inc(atomic_t *v)
77 asm volatile(LOCK_PREFIX "incl %0"
82 * atomic_dec - decrement atomic variable
83 * @v: pointer of type atomic_t
85 * Atomically decrements @v by 1.
87 static inline void atomic_dec(atomic_t *v)
89 asm volatile(LOCK_PREFIX "decl %0"
94 * atomic_inc_short - increment of a short integer
95 * @v: pointer to type int
97 * Atomically adds 1 to @v
98 * Returns the new value of @u
100 static inline short int atomic_inc_short(short int *v)
102 asm(LOCK_PREFIX "addw $1, %0" : "+m" (*v));
106 /* These are x86-specific, used by some header files */
107 #define atomic_clear_mask(mask, addr) \
108 asm volatile(LOCK_PREFIX "andl %0,%1" \
109 : : "r" (~(mask)), "m" (*(addr)) : "memory")
111 #define atomic_set_mask(mask, addr) \
112 asm volatile(LOCK_PREFIX "orl %0,%1" \
113 : : "r" ((unsigned)(mask)), "m" (*(addr)) \
116 #endif /* _ASM_X86_ATOMIC_H */