cmpxchg.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef _ALPHA_CMPXCHG_H
  2. #define _ALPHA_CMPXCHG_H
  3. /*
  4. * Atomic exchange routines.
  5. */
  6. #define __ASM__MB
  7. #define ____xchg(type, args...) __xchg ## type ## _local(args)
  8. #define ____cmpxchg(type, args...) __cmpxchg ## type ## _local(args)
  9. #include <asm/xchg.h>
  10. #define xchg_local(ptr, x) \
  11. ({ \
  12. __typeof__(*(ptr)) _x_ = (x); \
  13. (__typeof__(*(ptr))) __xchg_local((ptr), (unsigned long)_x_, \
  14. sizeof(*(ptr))); \
  15. })
  16. #define cmpxchg_local(ptr, o, n) \
  17. ({ \
  18. __typeof__(*(ptr)) _o_ = (o); \
  19. __typeof__(*(ptr)) _n_ = (n); \
  20. (__typeof__(*(ptr))) __cmpxchg_local((ptr), (unsigned long)_o_, \
  21. (unsigned long)_n_, \
  22. sizeof(*(ptr))); \
  23. })
  24. #define cmpxchg64_local(ptr, o, n) \
  25. ({ \
  26. BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
  27. cmpxchg_local((ptr), (o), (n)); \
  28. })
  29. #ifdef CONFIG_SMP
  30. #undef __ASM__MB
  31. #define __ASM__MB "\tmb\n"
  32. #endif
  33. #undef ____xchg
  34. #undef ____cmpxchg
  35. #define ____xchg(type, args...) __xchg ##type(args)
  36. #define ____cmpxchg(type, args...) __cmpxchg ##type(args)
  37. #include <asm/xchg.h>
  38. #define xchg(ptr, x) \
  39. ({ \
  40. __typeof__(*(ptr)) _x_ = (x); \
  41. (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, \
  42. sizeof(*(ptr))); \
  43. })
  44. #define cmpxchg(ptr, o, n) \
  45. ({ \
  46. __typeof__(*(ptr)) _o_ = (o); \
  47. __typeof__(*(ptr)) _n_ = (n); \
  48. (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
  49. (unsigned long)_n_, sizeof(*(ptr)));\
  50. })
  51. #define cmpxchg64(ptr, o, n) \
  52. ({ \
  53. BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
  54. cmpxchg((ptr), (o), (n)); \
  55. })
  56. #undef __ASM__MB
  57. #undef ____cmpxchg
  58. #endif /* _ALPHA_CMPXCHG_H */