atomic.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #define atomic_full_barrier() \
  22. __asm__ __volatile__("": : :"memory")
  23. /* Atomic compare and exchange. */
  24. #define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
  25. ({ __arc_link_error (); oldval; })
  26. #define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
  27. ({ __arc_link_error (); oldval; })
  28. #define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
  29. ({ \
  30. __typeof(oldval) prev; \
  31. \
  32. __asm__ __volatile__( \
  33. "1: llock %0, [%1] \n" \
  34. " brne %0, %2, 2f \n" \
  35. " scond %3, [%1] \n" \
  36. " bnz 1b \n" \
  37. "2: \n" \
  38. : "=&r"(prev) \
  39. : "r"(mem), "ir"(oldval), \
  40. "r"(newval) /* can't be "ir". scond can't take limm for "b" */\
  41. : "cc", "memory"); \
  42. \
  43. prev; \
  44. })
  45. #define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
  46. ({ __arc_link_error (); oldval; })