atomic-irq.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef __ASM_SH_ATOMIC_IRQ_H
  2. #define __ASM_SH_ATOMIC_IRQ_H
  3. #include <linux/irqflags.h>
  4. /*
  5. * To get proper branch prediction for the main line, we must branch
  6. * forward to code at the end of this object's .text section, then
  7. * branch back to restart the operation.
  8. */
  9. static inline void atomic_add(int i, atomic_t *v)
  10. {
  11. unsigned long flags;
  12. raw_local_irq_save(flags);
  13. v->counter += i;
  14. raw_local_irq_restore(flags);
  15. }
  16. static inline void atomic_sub(int i, atomic_t *v)
  17. {
  18. unsigned long flags;
  19. raw_local_irq_save(flags);
  20. v->counter -= i;
  21. raw_local_irq_restore(flags);
  22. }
  23. static inline int atomic_add_return(int i, atomic_t *v)
  24. {
  25. unsigned long temp, flags;
  26. raw_local_irq_save(flags);
  27. temp = v->counter;
  28. temp += i;
  29. v->counter = temp;
  30. raw_local_irq_restore(flags);
  31. return temp;
  32. }
  33. static inline int atomic_sub_return(int i, atomic_t *v)
  34. {
  35. unsigned long temp, flags;
  36. raw_local_irq_save(flags);
  37. temp = v->counter;
  38. temp -= i;
  39. v->counter = temp;
  40. raw_local_irq_restore(flags);
  41. return temp;
  42. }
  43. static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
  44. {
  45. unsigned long flags;
  46. raw_local_irq_save(flags);
  47. v->counter &= ~mask;
  48. raw_local_irq_restore(flags);
  49. }
  50. static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
  51. {
  52. unsigned long flags;
  53. raw_local_irq_save(flags);
  54. v->counter |= mask;
  55. raw_local_irq_restore(flags);
  56. }
  57. #endif /* __ASM_SH_ATOMIC_IRQ_H */