atomic.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * Licensed under LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <stdint.h>
  7. #include <sysdep.h>
  8. typedef int8_t atomic8_t;
  9. typedef uint8_t uatomic8_t;
  10. typedef int_fast8_t atomic_fast8_t;
  11. typedef uint_fast8_t uatomic_fast8_t;
  12. typedef int32_t atomic32_t;
  13. typedef uint32_t uatomic32_t;
  14. typedef int_fast32_t atomic_fast32_t;
  15. typedef uint_fast32_t uatomic_fast32_t;
  16. typedef intptr_t atomicptr_t;
  17. typedef uintptr_t uatomicptr_t;
  18. typedef intmax_t atomic_max_t;
  19. typedef uintmax_t uatomic_max_t;
  20. void __arc_link_error (void);
  21. #ifdef __A7__
  22. #define atomic_full_barrier() __asm__ __volatile__("": : :"memory")
  23. #else
  24. #define atomic_full_barrier() __asm__ __volatile__("dmb 3": : :"memory")
  25. #endif
  26. /* Atomic compare and exchange. */
  27. #define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
  28. ({ __arc_link_error (); oldval; })
  29. #define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
  30. ({ __arc_link_error (); oldval; })
  31. #define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
  32. ({ \
  33. __typeof(oldval) prev; \
  34. \
  35. __asm__ __volatile__( \
  36. "1: llock %0, [%1] \n" \
  37. " brne %0, %2, 2f \n" \
  38. " scond %3, [%1] \n" \
  39. " bnz 1b \n" \
  40. "2: \n" \
  41. : "=&r"(prev) \
  42. : "r"(mem), "ir"(oldval), \
  43. "r"(newval) /* can't be "ir". scond can't take limm for "b" */\
  44. : "cc", "memory"); \
  45. \
  46. prev; \
  47. })
  48. #define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
  49. ({ __arc_link_error (); oldval; })