cmpxchg.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef _ASM_SCORE_CMPXCHG_H
  2. #define _ASM_SCORE_CMPXCHG_H
  3. #include <linux/irqflags.h>
  4. struct __xchg_dummy { unsigned long a[100]; };
  5. #define __xg(x) ((struct __xchg_dummy *)(x))
  6. static inline
  7. unsigned long __xchg(volatile unsigned long *m, unsigned long val)
  8. {
  9. unsigned long retval;
  10. unsigned long flags;
  11. local_irq_save(flags);
  12. retval = *m;
  13. *m = val;
  14. local_irq_restore(flags);
  15. return retval;
  16. }
  17. #define xchg(ptr, v) \
  18. ((__typeof__(*(ptr))) __xchg((unsigned long *)(ptr), \
  19. (unsigned long)(v)))
  20. static inline unsigned long __cmpxchg(volatile unsigned long *m,
  21. unsigned long old, unsigned long new)
  22. {
  23. unsigned long retval;
  24. unsigned long flags;
  25. local_irq_save(flags);
  26. retval = *m;
  27. if (retval == old)
  28. *m = new;
  29. local_irq_restore(flags);
  30. return retval;
  31. }
  32. #define cmpxchg(ptr, o, n) \
  33. ((__typeof__(*(ptr))) __cmpxchg((unsigned long *)(ptr), \
  34. (unsigned long)(o), \
  35. (unsigned long)(n)))
  36. #define __HAVE_ARCH_CMPXCHG 1
  37. #include <asm-generic/cmpxchg-local.h>
  38. #endif /* _ASM_SCORE_CMPXCHG_H */