aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/threading/spin_lock_count.cpp
blob: 501a8bd73e7efea02c8be055043f46fd7163daa8 (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
#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::NPrivate {

#ifndef NDEBUG

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

YT_THREAD_LOCAL(i64) ActiveSpinLockCount = 0;

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

void RecordSpinLockAcquired(bool isAcquired)
{
    if (isAcquired) {
        ActiveSpinLockCount++;
    }
}

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

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

#endif

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

} // namespace NYT::NThreading::NPrivate