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