blob: 1fa1dd737b49b0615ab354df6b0af548a2e3df04 (
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
|
#pragma once
#include "rw_spin_lock.h"
namespace NYT::NThreading {
////////////////////////////////////////////////////////////////////////////////
//! Wraps TReaderWriterSpinLock and additionally acquires a global fork lock (in read mode)
//! preventing concurrent forks from happening.
class TForkAwareReaderWriterSpinLock
{
public:
TForkAwareReaderWriterSpinLock() = default;
TForkAwareReaderWriterSpinLock(const TForkAwareReaderWriterSpinLock&) = delete;
TForkAwareReaderWriterSpinLock& operator =(const TForkAwareReaderWriterSpinLock&) = delete;
// TODO(babenko): make use of location.
explicit constexpr TForkAwareReaderWriterSpinLock(const ::TSourceLocation& /*location*/)
{ }
void AcquireReader() noexcept;
void ReleaseReader() noexcept;
void AcquireWriter() noexcept;
void ReleaseWriter() noexcept;
bool IsLocked() const noexcept;
bool IsLockedByReader() const noexcept;
bool IsLockedByWriter() const noexcept;
private:
TReaderWriterSpinLock SpinLock_;
};
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT::NThreading
|