aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/threading/spin_wait.h
blob: afbccaee2bef090615e215585f17509beafba5e6 (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
#pragma once

#include "spin_wait_hook.h"

#include <library/cpp/yt/cpu_clock/clock.h>

#include <util/datetime/base.h>

#include <util/system/src_location.h>

namespace NYT::NThreading {

////////////////////////////////////////////////////////////////////////////////

class TSpinWait
{
public:
    TSpinWait(
        const ::TSourceLocation& location,
        ESpinLockActivityKind activityKind);
    ~TSpinWait();

    void Wait();

private:
    const ::TSourceLocation Location_;
    const ESpinLockActivityKind ActivityKind_;

    int SpinIteration_ = 0;
    int SleepIteration_ = 0;

    TCpuInstant SlowPathStartInstant_ = -1;
};

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NThreading