cmpxchg.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * cmpxchg.h -- forked from asm/atomic.h with this copyright:
  3. *
  4. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation, version 2.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  13. * NON INFRINGEMENT. See the GNU General Public License for
  14. * more details.
  15. *
  16. */
  17. #ifndef _ASM_TILE_CMPXCHG_H
  18. #define _ASM_TILE_CMPXCHG_H
  19. #ifndef __ASSEMBLY__
  20. /* Nonexistent functions intended to cause link errors. */
  21. extern unsigned long __xchg_called_with_bad_pointer(void);
  22. extern unsigned long __cmpxchg_called_with_bad_pointer(void);
  23. #define xchg(ptr, x) \
  24. ({ \
  25. typeof(*(ptr)) __x; \
  26. switch (sizeof(*(ptr))) { \
  27. case 4: \
  28. __x = (typeof(__x))(typeof(__x-__x))atomic_xchg( \
  29. (atomic_t *)(ptr), \
  30. (u32)(typeof((x)-(x)))(x)); \
  31. break; \
  32. case 8: \
  33. __x = (typeof(__x))(typeof(__x-__x))atomic64_xchg( \
  34. (atomic64_t *)(ptr), \
  35. (u64)(typeof((x)-(x)))(x)); \
  36. break; \
  37. default: \
  38. __xchg_called_with_bad_pointer(); \
  39. } \
  40. __x; \
  41. })
  42. #define cmpxchg(ptr, o, n) \
  43. ({ \
  44. typeof(*(ptr)) __x; \
  45. switch (sizeof(*(ptr))) { \
  46. case 4: \
  47. __x = (typeof(__x))(typeof(__x-__x))atomic_cmpxchg( \
  48. (atomic_t *)(ptr), \
  49. (u32)(typeof((o)-(o)))(o), \
  50. (u32)(typeof((n)-(n)))(n)); \
  51. break; \
  52. case 8: \
  53. __x = (typeof(__x))(typeof(__x-__x))atomic64_cmpxchg( \
  54. (atomic64_t *)(ptr), \
  55. (u64)(typeof((o)-(o)))(o), \
  56. (u64)(typeof((n)-(n)))(n)); \
  57. break; \
  58. default: \
  59. __cmpxchg_called_with_bad_pointer(); \
  60. } \
  61. __x; \
  62. })
  63. #define tas(ptr) (xchg((ptr), 1))
  64. #endif /* __ASSEMBLY__ */
  65. #endif /* _ASM_TILE_CMPXCHG_H */