Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HandleCollector.cs
Go to the documentation of this file.
2
4
5public sealed class HandleCollector
6{
7 private int _threshold;
8
9 private int _handleCount;
10
11 private readonly int[] _gcCounts = new int[3];
12
13 private int _gcGeneration;
14
15 public int Count => _handleCount;
16
17 public int InitialThreshold { get; }
18
19 public int MaximumThreshold { get; }
20
21 public string Name { get; }
22
23 public HandleCollector(string? name, int initialThreshold)
24 : this(name, initialThreshold, int.MaxValue)
25 {
26 }
27
28 public HandleCollector(string? name, int initialThreshold, int maximumThreshold)
29 {
30 if (initialThreshold < 0)
31 {
32 throw new ArgumentOutOfRangeException("initialThreshold", initialThreshold, System.SR.Arg_NeedNonNegNumRequired);
33 }
34 if (maximumThreshold < 0)
35 {
36 throw new ArgumentOutOfRangeException("maximumThreshold", maximumThreshold, System.SR.Arg_NeedNonNegNumRequired);
37 }
38 if (initialThreshold > maximumThreshold)
39 {
40 throw new ArgumentException(System.SR.Arg_InvalidThreshold, "initialThreshold");
41 }
42 Name = name ?? string.Empty;
43 InitialThreshold = initialThreshold;
44 MaximumThreshold = maximumThreshold;
45 _threshold = initialThreshold;
46 _handleCount = 0;
47 }
48
49 public void Add()
50 {
51 int num = -1;
53 if (_handleCount < 0)
54 {
56 }
58 {
59 lock (this)
60 {
62 num = _gcGeneration;
63 if (_gcGeneration < 2)
64 {
66 }
67 }
68 }
69 if (num >= 0 && (num == 0 || _gcCounts[num] == GC.CollectionCount(num)))
70 {
71 GC.Collect(num);
72 Thread.Sleep(10 * num);
73 }
74 for (int i = 1; i < 3; i++)
75 {
77 }
78 }
79
80 public void Remove()
81 {
83 if (_handleCount < 0)
84 {
86 }
87 int num = _handleCount + _handleCount / 10;
88 if (num < _threshold - _threshold / 10)
89 {
90 lock (this)
91 {
92 if (num > InitialThreshold)
93 {
94 _threshold = num;
95 }
96 else
97 {
99 }
100 _gcGeneration = 0;
101 }
102 }
103 for (int i = 1; i < 3; i++)
104 {
106 }
107 }
108}
static int CollectionCount(int generation)
Definition GC.cs:169
static void Collect(int generation)
Definition GC.cs:119
Definition GC.cs:8
HandleCollector(string? name, int initialThreshold)
HandleCollector(string? name, int initialThreshold, int maximumThreshold)
static string Arg_InvalidThreshold
Definition SR.cs:18
static string Arg_NeedNonNegNumRequired
Definition SR.cs:16
static string InvalidOperation_HCCountOverflow
Definition SR.cs:14
Definition SR.cs:7
static int Decrement(ref int location)
static int Increment(ref int location)
static void Sleep(int millisecondsTimeout)
Definition Thread.cs:658