blob: b36e0e20515d7f48144e3f32b89e1ce3706e7ee9 [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001#ifndef SMP_ATOMIC_H
2#define SMP_ATOMIC_H
3
4#ifdef SMP
5#include <arch/smp/atomic.h>
6#else
7
8typedef struct { int counter; } atomic_t;
9#define ATOMIC_INIT(i) { (i) }
10
11/**
12 * atomic_read - read atomic variable
13 * @v: pointer of type atomic_t
14 *
15 * Atomically reads the value of @v. Note that the guaranteed
16 * useful range of an atomic_t is only 24 bits.
17 */
18#define atomic_read(v) ((v)->counter)
19
20/**
21 * atomic_set - set atomic variable
22 * @v: pointer of type atomic_t
23 * @i: required value
24 *
25 * Atomically sets the value of @v to @i. Note that the guaranteed
26 * useful range of an atomic_t is only 24 bits.
27 */
28#define atomic_set(v,i) (((v)->counter) = (i))
29
30
31/**
32 * atomic_inc - increment atomic variable
33 * @v: pointer of type atomic_t
34 *
35 * Atomically increments @v by 1. Note that the guaranteed
36 * useful range of an atomic_t is only 24 bits.
37 */
38#define atomic_inc(v) (((v)->counter)++)
39
40
41/**
42 * atomic_dec - decrement atomic variable
43 * @v: pointer of type atomic_t
44 *
45 * Atomically decrements @v by 1. Note that the guaranteed
46 * useful range of an atomic_t is only 24 bits.
47 */
48#define atomic_dec(v) (((v)->counter)--)
49
50
51#endif /* SMP */
52
53#endif /* SMP_ATOMIC_H */