Michal Simek | 10713b1 | 2009-03-27 14:25:36 +0100 | [diff] [blame] | 1 | #ifndef _ASM_MICROBLAZE_ATOMIC_H |
| 2 | #define _ASM_MICROBLAZE_ATOMIC_H |
| 3 | |
David Howells | c40d04d | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 4 | #include <asm/cmpxchg.h> |
Remis Lima Baima | 0a58458 | 2009-06-18 19:55:33 +0200 | [diff] [blame] | 5 | #include <asm-generic/atomic.h> |
Daniel Borkmann | eacb6ec | 2012-01-19 12:37:13 +0100 | [diff] [blame] | 6 | #include <asm-generic/atomic64.h> |
Michal Simek | 10713b1 | 2009-03-27 14:25:36 +0100 | [diff] [blame] | 7 | |
| 8 | /* |
| 9 | * Atomically test *v and decrement if it is greater than 0. |
| 10 | * The function returns the old value of *v minus 1. |
| 11 | */ |
| 12 | static inline int atomic_dec_if_positive(atomic_t *v) |
| 13 | { |
| 14 | unsigned long flags; |
| 15 | int res; |
| 16 | |
| 17 | local_irq_save(flags); |
| 18 | res = v->counter - 1; |
| 19 | if (res >= 0) |
| 20 | v->counter = res; |
| 21 | local_irq_restore(flags); |
| 22 | |
| 23 | return res; |
| 24 | } |
| 25 | |
Michal Simek | 10713b1 | 2009-03-27 14:25:36 +0100 | [diff] [blame] | 26 | #endif /* _ASM_MICROBLAZE_ATOMIC_H */ |