spin_wait.h 752 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include "spin_wait_hook.h"
  3. #include <library/cpp/yt/cpu_clock/clock.h>
  4. #include <util/datetime/base.h>
  5. #include <util/system/src_location.h>
  6. namespace NYT::NThreading {
  7. ////////////////////////////////////////////////////////////////////////////////
  8. class TSpinWait
  9. {
  10. public:
  11. TSpinWait(
  12. const ::TSourceLocation& location,
  13. ESpinLockActivityKind activityKind);
  14. ~TSpinWait();
  15. void Wait();
  16. private:
  17. const ::TSourceLocation Location_;
  18. const ESpinLockActivityKind ActivityKind_;
  19. int SpinIteration_ = 0;
  20. int SleepIteration_ = 0;
  21. TCpuInstant SlowPathStartInstant_ = -1;
  22. };
  23. ////////////////////////////////////////////////////////////////////////////////
  24. } // namespace NYT::NThreading