Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LowLevelLock.cs
Go to the documentation of this file.
1namespace System.Threading;
2
3internal sealed class LowLevelLock : IDisposable
4{
5 private int _state;
6
8
10
11 private readonly Func<bool> _spinWaitTryAcquireCallback;
12
14
21
23 {
24 Dispose();
25 }
26
27 public void Dispose()
28 {
30 GC.SuppressFinalize(this);
31 }
32
33 public bool TryAcquire()
34 {
35 int num = Interlocked.CompareExchange(ref _state, 1, 0);
36 if (num == 0 || TryAcquire_NoFastPath(num))
37 {
38 return true;
39 }
40 return false;
41 }
42
43 private bool TryAcquire_NoFastPath(int state)
44 {
45 if ((state & 1) == 0)
46 {
48 }
49 return false;
50 }
51
53 {
55 }
56
57 public void Acquire()
58 {
59 if (!TryAcquire())
60 {
62 }
63 }
64
65 private void WaitAndAcquire()
66 {
68 {
70 int num = Interlocked.Add(ref _state, 2);
71 while (((uint)num & (true ? 1u : 0u)) != 0 || Interlocked.CompareExchange(ref _state, num + -1, num) != num)
72 {
73 _monitor.Wait();
75 num = _state;
76 }
78 }
79 }
80
81 public void Release()
82 {
83 if (Interlocked.Decrement(ref _state) != 0)
84 {
86 }
87 }
88
89 private void SignalWaiter()
90 {
92 if ((uint)_state >= 2u && !_isAnyWaitingThreadSignaled)
93 {
96 }
97 else
98 {
100 }
101 }
102}
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static int CompareExchange(ref int location1, int value, int comparand)
static int Decrement(ref int location)
static int Add(ref int location1, int value)
bool TryAcquire_NoFastPath(int state)
readonly Func< bool > _spinWaitTryAcquireCallback
LowLevelSpinWaiter _spinWaiter
bool SpinWaitForCondition(Func< bool > condition, int spinCount, int sleep0Threshold)