atomic.h 626 B

12345678910111213141516171819202122232425262728
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_MICROBLAZE_ATOMIC_H
  3. #define _ASM_MICROBLAZE_ATOMIC_H
  4. #include <asm/cmpxchg.h>
  5. #include <asm-generic/atomic.h>
  6. #include <asm-generic/atomic64.h>
  7. /*
  8. * Atomically test *v and decrement if it is greater than 0.
  9. * The function returns the old value of *v minus 1.
  10. */
  11. static inline int atomic_dec_if_positive(atomic_t *v)
  12. {
  13. unsigned long flags;
  14. int res;
  15. local_irq_save(flags);
  16. res = v->counter - 1;
  17. if (res >= 0)
  18. v->counter = res;
  19. local_irq_restore(flags);
  20. return res;
  21. }
  22. #define atomic_dec_if_positive atomic_dec_if_positive
  23. #endif /* _ASM_MICROBLAZE_ATOMIC_H */