thread_extra.h 976 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include <util/thread/singleton.h>
  3. namespace NTSAN {
  4. template <typename T>
  5. inline void RelaxedStore(volatile T* a, T x) {
  6. static_assert(std::is_integral<T>::value || std::is_pointer<T>::value, "expect std::is_integral<T>::value || std::is_pointer<T>::value");
  7. #ifdef _win_
  8. *a = x;
  9. #else
  10. __atomic_store_n(a, x, __ATOMIC_RELAXED);
  11. #endif
  12. }
  13. template <typename T>
  14. inline T RelaxedLoad(volatile T* a) {
  15. #ifdef _win_
  16. return *a;
  17. #else
  18. return __atomic_load_n(a, __ATOMIC_RELAXED);
  19. #endif
  20. }
  21. }
  22. void SetCurrentThreadName(const char* name);
  23. namespace NThreadExtra {
  24. namespace NPrivate {
  25. template <typename TValue, typename TTag>
  26. struct TValueHolder {
  27. TValue Value;
  28. };
  29. }
  30. }
  31. template <typename TValue, typename TTag>
  32. static inline TValue* FastTlsSingletonWithTag() {
  33. return &FastTlsSingleton< ::NThreadExtra::NPrivate::TValueHolder<TValue, TTag>>()->Value;
  34. }