Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame^] | 1 | #ifndef SMP_ATOMIC_H |
| 2 | #define SMP_ATOMIC_H |
| 3 | |
| 4 | #ifdef SMP |
| 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 |
| 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 */ |