atomic-irq.h 1.3 KB

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