summaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/threading/spin_lock_count.cpp
blob: 008a5a66ad52c394fe7e7d047f9288c3b3df9b2c (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
38
39
40
41
42
43
44
45
46
47
48

#include "spin_lock_count.h"

#include <library/cpp/yt/assert/assert.h>

#include <library/cpp/yt/misc/tls.h>

#include <util/system/types.h>

namespace NYT::NThreading {

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

#ifndef NDEBUG

namespace NDetail {

YT_DEFINE_THREAD_LOCAL(i64, ActiveSpinLockCount, 0);

void RecordSpinLockAcquired()
{
    ActiveSpinLockCount()++;
}

void RecordSpinLockReleased()
{
    YT_VERIFY(ActiveSpinLockCount() > 0);
    ActiveSpinLockCount()--;
}

} // namespace NDetail

int GetActiveSpinLockCount()
{
    return NDetail::ActiveSpinLockCount();
}

void VerifyNoSpinLockAffinity()
{
    YT_VERIFY(NDetail::ActiveSpinLockCount() == 0);
}

#endif

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

} // namespace NYT::NThreading