Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SynchronizedList.cs
Go to the documentation of this file.
2
3namespace System.Diagnostics;
4
5internal sealed class SynchronizedList<T>
6{
7 private readonly List<T> _list;
8
9 private uint _version;
10
11 public int Count => _list.Count;
12
14 {
15 _list = new List<T>();
16 }
17
18 public void Add(T item)
19 {
20 lock (_list)
21 {
22 _list.Add(item);
23 _version++;
24 }
25 }
26
27 public bool AddIfNotExist(T item)
28 {
29 lock (_list)
30 {
31 if (!_list.Contains(item))
32 {
33 _list.Add(item);
34 _version++;
35 return true;
36 }
37 return false;
38 }
39 }
40
41 public bool Remove(T item)
42 {
43 lock (_list)
44 {
45 if (_list.Remove(item))
46 {
47 _version++;
48 return true;
49 }
50 return false;
51 }
52 }
53
55 {
56 uint version = _version;
57 int num = 0;
58 while (num < _list.Count)
59 {
60 T item;
61 lock (_list)
62 {
63 if (version != _version)
64 {
65 version = _version;
66 num = 0;
67 continue;
68 }
69 item = _list[num];
70 num++;
71 }
73 }
74 }
75
77 {
78 uint version = _version;
79 int num = 0;
80 while (num < _list.Count)
81 {
82 T arg2;
83 lock (_list)
84 {
85 if (version != _version)
86 {
87 version = _version;
88 num = 0;
89 continue;
90 }
91 arg2 = _list[num];
92 num++;
93 }
94 action(arg2, arg);
95 }
96 }
97}
void EnumWithAction(Action< T, object > action, object arg)
void EnumWithFunc< TParent >(ActivitySource.Function< T, TParent > func, ref ActivityCreationOptions< TParent > data, ref ActivitySamplingResult samplingResult, ref ActivityCreationOptions< ActivityContext > dataWithContext)