aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/threading/rw_spin_lock.cpp
blob: cd37f10a22f57ee08008c982ce95a9eee7de0756 (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
#include "rw_spin_lock.h"

namespace NYT::NThreading {

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

void TReaderWriterSpinLock::AcquireReaderSlow() noexcept
{
    TSpinWait spinWait(Location_, ESpinLockActivityKind::Read);
    while (!TryAndTryAcquireReader()) {
        spinWait.Wait();
    }
}

void TReaderWriterSpinLock::AcquireReaderForkFriendlySlow() noexcept
{
    TSpinWait spinWait(Location_, ESpinLockActivityKind::Read);
    while (!TryAcquireReaderForkFriendly()) {
        spinWait.Wait();
    }
}

void TReaderWriterSpinLock::AcquireWriterSlow() noexcept
{
    TSpinWait spinWait(Location_, ESpinLockActivityKind::Write);
    while (!TryAndTryAcquireWriter()) {
        spinWait.Wait();
    }
}

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

} // namespace NYT::NThreading