cmpxchg.h 851 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef _ASM_MICROBLAZE_CMPXCHG_H
  2. #define _ASM_MICROBLAZE_CMPXCHG_H
  3. void __bad_xchg(volatile void *ptr, int size);
  4. static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
  5. int size)
  6. {
  7. unsigned long ret;
  8. unsigned long flags;
  9. switch (size) {
  10. case 1:
  11. local_irq_save(flags);
  12. ret = *(volatile unsigned char *)ptr;
  13. *(volatile unsigned char *)ptr = x;
  14. local_irq_restore(flags);
  15. break;
  16. case 4:
  17. local_irq_save(flags);
  18. ret = *(volatile unsigned long *)ptr;
  19. *(volatile unsigned long *)ptr = x;
  20. local_irq_restore(flags);
  21. break;
  22. default:
  23. __bad_xchg(ptr, size), ret = 0;
  24. break;
  25. }
  26. return ret;
  27. }
  28. #define xchg(ptr, x) \
  29. ((__typeof__(*(ptr))) __xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
  30. #include <asm-generic/cmpxchg.h>
  31. #include <asm-generic/cmpxchg-local.h>
  32. #endif /* _ASM_MICROBLAZE_CMPXCHG_H */