#include "spin_wait_hook.h" #include #include #include namespace NYT::NThreading { //////////////////////////////////////////////////////////////////////////////// static constexpr int MaxSpinWaitSlowPathHooks = 8; static std::array, MaxSpinWaitSlowPathHooks> SpinWaitSlowPathHooks; static std::atomic SpinWaitSlowPathHookCount; void RegisterSpinWaitSlowPathHook(TSpinWaitSlowPathHook hook) { int index = SpinWaitSlowPathHookCount++; YT_VERIFY(index < MaxSpinWaitSlowPathHooks); SpinWaitSlowPathHooks[index].store(hook); } void InvokeSpinWaitSlowPathHooks( TCpuDuration cpuDelay, const ::TSourceLocation& location, ESpinLockActivityKind activityKind) { for (const auto& atomicHook : SpinWaitSlowPathHooks) { if (auto hook = atomicHook.load()) { hook(cpuDelay, location, activityKind); } } } //////////////////////////////////////////////////////////////////////////////// } // namespace NYT::NThreading