1 #ifndef ARCH_SMP_ATOMIC_H
2 #define ARCH_SMP_ATOMIC_H
5 * Make sure gcc doesn't try to be clever and move things around
6 * on us. We need to use _exactly_ the address the user gave us,
7 * not some alias that contains the same information.
9 typedef struct { volatile int counter; } atomic_t;
11 #define ATOMIC_INIT(i) { (i) }
14 * Atomic operations that C can't guarantee us. Useful for
15 * resource counting etc..
19 * atomic_read - read atomic variable
20 * @v: pointer of type atomic_t
22 * Atomically reads the value of @v. Note that the guaranteed
23 * useful range of an atomic_t is only 24 bits.
25 #define atomic_read(v) ((v)->counter)
28 * atomic_set - set atomic variable
29 * @v: pointer of type atomic_t
32 * Atomically sets the value of @v to @i. Note that the guaranteed
33 * useful range of an atomic_t is only 24 bits.
35 #define atomic_set(v,i) (((v)->counter) = (i))
38 * atomic_inc - increment atomic variable
39 * @v: pointer of type atomic_t
41 * Atomically increments @v by 1. Note that the guaranteed
42 * useful range of an atomic_t is only 24 bits.
44 static __inline__ __attribute__((always_inline)) void atomic_inc(atomic_t *v)
53 * atomic_dec - decrement atomic variable
54 * @v: pointer of type atomic_t
56 * Atomically decrements @v by 1. Note that the guaranteed
57 * useful range of an atomic_t is only 24 bits.
59 static __inline__ __attribute__((always_inline)) void atomic_dec(atomic_t *v)
69 #endif /* ARCH_SMP_ATOMIC_H */