blob: fbcc9a44cda8751813816653d175b98e52f9b347 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include "spin_wait_hook.h"
#include <library/cpp/yt/assert/assert.h>
#include <array>
#include <atomic>
namespace NYT::NThreading {
////////////////////////////////////////////////////////////////////////////////
static constexpr int MaxSpinWaitSlowPathHooks = 8;
static std::array<std::atomic<TSpinWaitSlowPathHook>, MaxSpinWaitSlowPathHooks> SpinWaitSlowPathHooks;
static std::atomic<int> 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
|