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 | /** |
Martin Roth | 24e2e95 | 2014-12-29 22:36:06 -0700 | [diff] [blame^] | 12 | * @file include/smp/atomic.h |
| 13 | */ |
| 14 | |
| 15 | /** |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 16 | * atomic_read - read atomic variable |
Martin Roth | 24e2e95 | 2014-12-29 22:36:06 -0700 | [diff] [blame^] | 17 | * @param v: pointer of type atomic_t |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 18 | * |
Martin Roth | 24e2e95 | 2014-12-29 22:36:06 -0700 | [diff] [blame^] | 19 | * Atomically reads the value of v. Note that the guaranteed |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 20 | * useful range of an atomic_t is only 24 bits. |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 21 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 22 | #define atomic_read(v) ((v)->counter) |
| 23 | |
| 24 | /** |
| 25 | * atomic_set - set atomic variable |
Martin Roth | 24e2e95 | 2014-12-29 22:36:06 -0700 | [diff] [blame^] | 26 | * @param v: pointer of type atomic_t |
| 27 | * @param i: required value |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 28 | * |
Martin Roth | 24e2e95 | 2014-12-29 22:36:06 -0700 | [diff] [blame^] | 29 | * Atomically sets the value of v to i. Note that the guaranteed |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 30 | * useful range of an atomic_t is only 24 bits. |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 31 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 32 | #define atomic_set(v,i) (((v)->counter) = (i)) |
| 33 | |
| 34 | |
| 35 | /** |
| 36 | * atomic_inc - increment atomic variable |
Martin Roth | 24e2e95 | 2014-12-29 22:36:06 -0700 | [diff] [blame^] | 37 | * @param v: pointer of type atomic_t |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 38 | * |
Martin Roth | 24e2e95 | 2014-12-29 22:36:06 -0700 | [diff] [blame^] | 39 | * Atomically increments v by 1. Note that the guaranteed |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 40 | * useful range of an atomic_t is only 24 bits. |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 41 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 42 | #define atomic_inc(v) (((v)->counter)++) |
| 43 | |
| 44 | |
| 45 | /** |
| 46 | * atomic_dec - decrement atomic variable |
Martin Roth | 24e2e95 | 2014-12-29 22:36:06 -0700 | [diff] [blame^] | 47 | * @param v: pointer of type atomic_t |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 48 | * |
Martin Roth | 24e2e95 | 2014-12-29 22:36:06 -0700 | [diff] [blame^] | 49 | * Atomically decrements v by 1. Note that the guaranteed |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 50 | * useful range of an atomic_t is only 24 bits. |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 51 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 52 | #define atomic_dec(v) (((v)->counter)--) |
| 53 | |
| 54 | |
Eric Biederman | 2c018fb | 2003-07-21 20:13:45 +0000 | [diff] [blame] | 55 | #endif /* CONFIG_SMP */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 56 | |
| 57 | #endif /* SMP_ATOMIC_H */ |