blob: 44be4c5c01ab0879975aa7e5a4b95f950aa605f9 [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001#ifndef SMP_ATOMIC_H
2#define SMP_ATOMIC_H
3
Patrick Georgie1667822012-05-05 15:29:32 +02004#if CONFIG_SMP
Eric Biederman8ca8d762003-04-22 19:02:15 +00005#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
Stefan Reinauer14e22772010-04-27 06:56:47 +000014 *
Eric Biederman8ca8d762003-04-22 19:02:15 +000015 * Atomically reads the value of @v. Note that the guaranteed
16 * useful range of an atomic_t is only 24 bits.
Stefan Reinauer14e22772010-04-27 06:56:47 +000017 */
Eric Biederman8ca8d762003-04-22 19:02:15 +000018#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
Stefan Reinauer14e22772010-04-27 06:56:47 +000024 *
Eric Biederman8ca8d762003-04-22 19:02:15 +000025 * Atomically sets the value of @v to @i. Note that the guaranteed
26 * useful range of an atomic_t is only 24 bits.
Stefan Reinauer14e22772010-04-27 06:56:47 +000027 */
Eric Biederman8ca8d762003-04-22 19:02:15 +000028#define atomic_set(v,i) (((v)->counter) = (i))
29
30
31/**
32 * atomic_inc - increment atomic variable
33 * @v: pointer of type atomic_t
Stefan Reinauer14e22772010-04-27 06:56:47 +000034 *
Eric Biederman8ca8d762003-04-22 19:02:15 +000035 * Atomically increments @v by 1. Note that the guaranteed
36 * useful range of an atomic_t is only 24 bits.
Stefan Reinauer14e22772010-04-27 06:56:47 +000037 */
Eric Biederman8ca8d762003-04-22 19:02:15 +000038#define atomic_inc(v) (((v)->counter)++)
39
40
41/**
42 * atomic_dec - decrement atomic variable
43 * @v: pointer of type atomic_t
Stefan Reinauer14e22772010-04-27 06:56:47 +000044 *
Eric Biederman8ca8d762003-04-22 19:02:15 +000045 * Atomically decrements @v by 1. Note that the guaranteed
46 * useful range of an atomic_t is only 24 bits.
Stefan Reinauer14e22772010-04-27 06:56:47 +000047 */
Eric Biederman8ca8d762003-04-22 19:02:15 +000048#define atomic_dec(v) (((v)->counter)--)
49
50
Eric Biederman2c018fb2003-07-21 20:13:45 +000051#endif /* CONFIG_SMP */
Eric Biederman8ca8d762003-04-22 19:02:15 +000052
53#endif /* SMP_ATOMIC_H */