Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ThreadInt64PersistentCounter.cs
Go to the documentation of this file.
4
5namespace System.Threading;
6
7internal sealed class ThreadInt64PersistentCounter
8{
9 private sealed class ThreadLocalNode
10 {
11 private uint _count;
12
14
15 public uint Count => _count;
16
21
22 public void Dispose()
23 {
25 s_lock.Acquire();
26 try
27 {
28 counter._overflowCount += _count;
29 counter._nodes.Remove(this);
30 }
31 finally
32 {
33 s_lock.Release();
34 }
35 }
36
37 [MethodImpl(MethodImplOptions.AggressiveInlining)]
38 public void Increment()
39 {
40 uint num = _count + 1;
41 if (num != 0)
42 {
43 _count = num;
44 }
45 else
46 {
48 }
49 }
50
51 [MethodImpl(MethodImplOptions.NoInlining)]
52 private void OnIncrementOverflow()
53 {
55 s_lock.Acquire();
56 try
57 {
58 _count = 0u;
59 counter._overflowCount += 4294967296L;
60 }
61 finally
62 {
63 s_lock.Release();
64 }
65 }
66 }
67
82
83 private static readonly LowLevelLock s_lock = new LowLevelLock();
84
87
88 private long _overflowCount;
89
91
92 public long Count
93 {
94 get
95 {
96 s_lock.Acquire();
97 long num = _overflowCount;
98 try
99 {
100 foreach (ThreadLocalNode node in _nodes)
101 {
102 num += node.Count;
103 }
104 }
106 {
107 }
108 finally
109 {
110 s_lock.Release();
111 }
112 return num;
113 }
114 }
115
116 [MethodImpl(MethodImplOptions.AggressiveInlining)]
117 public static void Increment(object threadLocalCountObject)
118 {
120 }
121
138}
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static void Increment(object threadLocalCountObject)
static List< ThreadLocalNodeFinalizationHelper > t_nodeFinalizationHelpers