blob: c4a6ae2ba8534bf4a75aef23cbb69d26023290ac (
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
|
#pragma once
#include "public.h"
#include "spin_lock.h"
#include <util/system/src_location.h>
namespace NYT::NThreading {
////////////////////////////////////////////////////////////////////////////////
//! Wraps TSpinLock and additionally acquires a global fork lock (in read mode)
//! preventing concurrent forks from happening.
class TForkAwareSpinLock
{
public:
static constexpr bool Traced = true;
TForkAwareSpinLock(const TForkAwareSpinLock&) = delete;
TForkAwareSpinLock& operator =(const TForkAwareSpinLock&) = delete;
constexpr TForkAwareSpinLock() = default;
explicit constexpr TForkAwareSpinLock(const ::TSourceLocation& location)
: SpinLock_(location)
{ }
void Acquire() noexcept;
bool TryAcquire() noexcept;
void Release() noexcept;
bool IsLocked() const noexcept;
private:
::NYT::NThreading::TSpinLock SpinLock_;
};
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT::NThreading
|