blob: bc505344429584d36b75e4d09d1e7c198afbdf55 [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/**
Martin Roth24e2e952014-12-29 22:36:06 -070012 * @file include/smp/atomic.h
13 */
14
15/**
Eric Biederman8ca8d762003-04-22 19:02:15 +000016 * atomic_read - read atomic variable
Martin Roth24e2e952014-12-29 22:36:06 -070017 * @param v: pointer of type atomic_t
Stefan Reinauer14e22772010-04-27 06:56:47 +000018 *
Martin Roth24e2e952014-12-29 22:36:06 -070019 * Atomically reads the value of v. Note that the guaranteed
Eric Biederman8ca8d762003-04-22 19:02:15 +000020 * useful range of an atomic_t is only 24 bits.
Stefan Reinauer14e22772010-04-27 06:56:47 +000021 */
Eric Biederman8ca8d762003-04-22 19:02:15 +000022#define atomic_read(v) ((v)->counter)
23
24/**
25 * atomic_set - set atomic variable
Martin Roth24e2e952014-12-29 22:36:06 -070026 * @param v: pointer of type atomic_t
27 * @param i: required value
Stefan Reinauer14e22772010-04-27 06:56:47 +000028 *
Martin Roth24e2e952014-12-29 22:36:06 -070029 * Atomically sets the value of v to i. Note that the guaranteed
Eric Biederman8ca8d762003-04-22 19:02:15 +000030 * useful range of an atomic_t is only 24 bits.
Stefan Reinauer14e22772010-04-27 06:56:47 +000031 */
Eric Biederman8ca8d762003-04-22 19:02:15 +000032#define atomic_set(v,i) (((v)->counter) = (i))
33
34
35/**
36 * atomic_inc - increment atomic variable
Martin Roth24e2e952014-12-29 22:36:06 -070037 * @param v: pointer of type atomic_t
Stefan Reinauer14e22772010-04-27 06:56:47 +000038 *
Martin Roth24e2e952014-12-29 22:36:06 -070039 * Atomically increments v by 1. Note that the guaranteed
Eric Biederman8ca8d762003-04-22 19:02:15 +000040 * useful range of an atomic_t is only 24 bits.
Stefan Reinauer14e22772010-04-27 06:56:47 +000041 */
Eric Biederman8ca8d762003-04-22 19:02:15 +000042#define atomic_inc(v) (((v)->counter)++)
43
44
45/**
46 * atomic_dec - decrement atomic variable
Martin Roth24e2e952014-12-29 22:36:06 -070047 * @param v: pointer of type atomic_t
Stefan Reinauer14e22772010-04-27 06:56:47 +000048 *
Martin Roth24e2e952014-12-29 22:36:06 -070049 * Atomically decrements v by 1. Note that the guaranteed
Eric Biederman8ca8d762003-04-22 19:02:15 +000050 * useful range of an atomic_t is only 24 bits.
Stefan Reinauer14e22772010-04-27 06:56:47 +000051 */
Eric Biederman8ca8d762003-04-22 19:02:15 +000052#define atomic_dec(v) (((v)->counter)--)
53
54
Eric Biederman2c018fb2003-07-21 20:13:45 +000055#endif /* CONFIG_SMP */
Eric Biederman8ca8d762003-04-22 19:02:15 +000056
57#endif /* SMP_ATOMIC_H */