You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
2.6 KiB

  1. commit 62aec002ccd6a7129b4f5e2e88be1957a6b2308b
  2. Author: Olivier Houchard <ohouchard@haproxy.com>
  3. Date: Thu Mar 7 18:48:22 2019 +0100
  4. MEDIUM: threads: Use __ATOMIC_SEQ_CST when using the newer atomic API.
  5. When using the new __atomic* API, ask the compiler to generate barriers.
  6. A variant of those functions that don't generate barriers will be added later.
  7. Before that, using HA_ATOMIC* would not generate any barrier, and some parts
  8. of the code should be reviewed and missing barriers should be added.
  9. This should probably be backported to 1.8 and 1.9.
  10. (cherry picked from commit 113537967c8680f94977473e18c9e14dc09c3356)
  11. [wt: this is in fact a real bug fix : all these atomics do not provide
  12. the slightest sequential consistency by default as the value 0 is
  13. __ATOMIC_RELAXED, which will definitely cause random issues with
  14. threads on non-x86 platforms].
  15. Signed-off-by: Willy Tarreau <w@1wt.eu>
  16. (cherry picked from commit e5d1670f5fa95972fed6391201c0da8982bb9f94)
  17. Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
  18. diff --git a/include/common/hathreads.h b/include/common/hathreads.h
  19. index 24fb1d1a..8a738aaf 100644
  20. --- a/include/common/hathreads.h
  21. +++ b/include/common/hathreads.h
  22. @@ -213,14 +213,14 @@ static inline unsigned long thread_isolated()
  23. })
  24. #else
  25. /* gcc >= 4.7 */
  26. -#define HA_ATOMIC_CAS(val, old, new) __atomic_compare_exchange_n(val, old, new, 0, 0, 0)
  27. -#define HA_ATOMIC_ADD(val, i) __atomic_add_fetch(val, i, 0)
  28. -#define HA_ATOMIC_XADD(val, i) __atomic_fetch_add(val, i, 0)
  29. -#define HA_ATOMIC_SUB(val, i) __atomic_sub_fetch(val, i, 0)
  30. -#define HA_ATOMIC_AND(val, flags) __atomic_and_fetch(val, flags, 0)
  31. -#define HA_ATOMIC_OR(val, flags) __atomic_or_fetch(val, flags, 0)
  32. -#define HA_ATOMIC_XCHG(val, new) __atomic_exchange_n(val, new, 0)
  33. -#define HA_ATOMIC_STORE(val, new) __atomic_store_n(val, new, 0)
  34. +#define HA_ATOMIC_CAS(val, old, new) __atomic_compare_exchange_n(val, old, new, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
  35. +#define HA_ATOMIC_ADD(val, i) __atomic_add_fetch(val, i, __ATOMIC_SEQ_CST)
  36. +#define HA_ATOMIC_XADD(val, i) __atomic_fetch_add(val, i, __ATOMIC_SEQ_CST)
  37. +#define HA_ATOMIC_SUB(val, i) __atomic_sub_fetch(val, i, __ATOMIC_SEQ_CST)
  38. +#define HA_ATOMIC_AND(val, flags) __atomic_and_fetch(val, flags, __ATOMIC_SEQ_CST)
  39. +#define HA_ATOMIC_OR(val, flags) __atomic_or_fetch(val, flags, __ATOMIC_SEQ_CST)
  40. +#define HA_ATOMIC_XCHG(val, new) __atomic_exchange_n(val, new, __ATOMIC_SEQ_CST)
  41. +#define HA_ATOMIC_STORE(val, new) __atomic_store_n(val, new, __ATOMIC_SEQ_CST)
  42. #endif
  43. #define HA_ATOMIC_UPDATE_MAX(val, new) \