Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | #ifndef SMP_ATOMIC_H |
| 2 | #define SMP_ATOMIC_H |
| 3 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame^] | 4 | #if CONFIG_SMP |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 5 | #include <arch/smp/atomic.h> |
| 6 | #else |
| 7 | |
| 8 | typedef 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 Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 14 | * |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 15 | * Atomically reads the value of @v. Note that the guaranteed |
| 16 | * useful range of an atomic_t is only 24 bits. |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 17 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 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 |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 24 | * |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 25 | * Atomically sets the value of @v to @i. Note that the guaranteed |
| 26 | * useful range of an atomic_t is only 24 bits. |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 27 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 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 |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 34 | * |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 35 | * Atomically increments @v by 1. Note that the guaranteed |
| 36 | * useful range of an atomic_t is only 24 bits. |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 37 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 38 | #define atomic_inc(v) (((v)->counter)++) |
| 39 | |
| 40 | |
| 41 | /** |
| 42 | * atomic_dec - decrement atomic variable |
| 43 | * @v: pointer of type atomic_t |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 44 | * |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 45 | * Atomically decrements @v by 1. Note that the guaranteed |
| 46 | * useful range of an atomic_t is only 24 bits. |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 47 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 48 | #define atomic_dec(v) (((v)->counter)--) |
| 49 | |
| 50 | |
Eric Biederman | 2c018fb | 2003-07-21 20:13:45 +0000 | [diff] [blame] | 51 | #endif /* CONFIG_SMP */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 52 | |
| 53 | #endif /* SMP_ATOMIC_H */ |