1#ifndef _ASM_X86_ATOMIC_H
2#define _ASM_X86_ATOMIC_H
3
4#include <linux/compiler.h>
5#include <linux/types.h>
6#include <asm/processor.h>
7
8typedef struct { volatile int counter; } atomic_t;
9
10
11
12
13
14
15#define ATOMIC_INIT(i) { (i) }
16
17
18
19
20
21
22
23static inline int atomic_read(const atomic_t *v)
24{
25 return ACCESS_ONCE((v)->counter);
26}
27
28
29
30
31
32
33
34
35static inline void atomic_set(atomic_t *v, int i)
36{
37 v->counter = i;
38}
39
40
41
42
43
44
45
46
47static inline void atomic_add(int i, atomic_t *v)
48{
49 asm volatile(LOCK_PREFIX "addl %1,%0"
50 : "+m" (v->counter)
51 : "ir" (i));
52}
53
54
55
56
57
58
59
60
61static inline void atomic_sub(int i, atomic_t *v)
62{
63 asm volatile(LOCK_PREFIX "subl %1,%0"
64 : "+m" (v->counter)
65 : "ir" (i));
66}
67
68
69
70
71
72
73
74static inline void atomic_inc(atomic_t *v)
75{
76 asm volatile(LOCK_PREFIX "incl %0"
77 : "+m" (v->counter));
78}
79
80
81
82
83
84
85
86static inline void atomic_dec(atomic_t *v)
87{
88 asm volatile(LOCK_PREFIX "decl %0"
89 : "+m" (v->counter));
90}
91
92
93
94
95
96
97
98
99static inline short int atomic_inc_short(short int *v)
100{
101 asm(LOCK_PREFIX "addw $1, %0" : "+m" (*v));
102 return *v;
103}
104
105
106#define atomic_clear_mask(mask, addr) \
107 asm volatile(LOCK_PREFIX "andl %0,%1" \
108 : : "r" (~(mask)), "m" (*(addr)) : "memory")
109
110#define atomic_set_mask(mask, addr) \
111 asm volatile(LOCK_PREFIX "orl %0,%1" \
112 : : "r" ((unsigned)(mask)), "m" (*(addr)) \
113 : "memory")
114
115#endif
116