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.

54 lines
2.2 KiB

  1. commit f95cf6ad70565ee2322cf23bc519b7bb0b3831b2
  2. Author: Olivier Houchard <ohouchard@haproxy.com>
  3. Date: Tue Apr 30 13:38:02 2019 +0200
  4. MINOR: threads: Implement HA_ATOMIC_LOAD().
  5. The same way we have HA_ATOMIC_STORE(), implement HA_ATOMIC_LOAD().
  6. This should be backported to 1.8 and 1.9, as we need it for a bug fix
  7. in port ranges.
  8. (cherry picked from commit 9ce62b5498b27fbf4217d9c25779d5b2ceca23f2)
  9. Signed-off-by: Olivier Houchard <cognet@ci0.org>
  10. (cherry picked from commit 358c979611370fa2bc3b8e47ed50a325cf9126cf)
  11. Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
  12. diff --git a/include/common/hathreads.h b/include/common/hathreads.h
  13. index 8134839a..11d7cab6 100644
  14. --- a/include/common/hathreads.h
  15. +++ b/include/common/hathreads.h
  16. @@ -62,6 +62,7 @@ enum { tid = 0 };
  17. *(val) = new; \
  18. __old_xchg; \
  19. })
  20. +#define HA_ATOMIC_LOAD(val) *(val)
  21. #define HA_ATOMIC_STORE(val, new) ({*(val) = new;})
  22. #define HA_ATOMIC_UPDATE_MAX(val, new) \
  23. ({ \
  24. @@ -203,6 +204,16 @@ static inline unsigned long thread_isolated()
  25. } while (!__sync_bool_compare_and_swap(__val_xchg, __old_xchg, __new_xchg)); \
  26. __old_xchg; \
  27. })
  28. +
  29. +#define HA_ATOMIC_LOAD(val) \
  30. + ({ \
  31. + typeof(*(val)) ret; \
  32. + __sync_synchronize(); \
  33. + ret = *(volatile typeof(val))val; \
  34. + __sync_synchronize(); \
  35. + ret; \
  36. + })
  37. +
  38. #define HA_ATOMIC_STORE(val, new) \
  39. ({ \
  40. typeof((val)) __val_store = (val); \
  41. @@ -221,6 +232,8 @@ static inline unsigned long thread_isolated()
  42. #define HA_ATOMIC_OR(val, flags) __atomic_or_fetch(val, flags, __ATOMIC_SEQ_CST)
  43. #define HA_ATOMIC_XCHG(val, new) __atomic_exchange_n(val, new, __ATOMIC_SEQ_CST)
  44. #define HA_ATOMIC_STORE(val, new) __atomic_store_n(val, new, __ATOMIC_SEQ_CST)
  45. +#define HA_ATOMIC_LOAD(val) __atomic_load_n(val, __ATOMIC_SEQ_CST)
  46. +
  47. #endif
  48. #define HA_ATOMIC_UPDATE_MAX(val, new) \