aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs
diff options
context:
space:
mode:
authorJohn Hurliman2009-10-08 21:51:53 -0700
committerJohn Hurliman2009-10-08 21:51:53 -0700
commit56a27c37d3e84495988e423be7b52007cea595cc (patch)
tree8452b3cfbf82e00f4188a1eefadc502b042a06e3 /OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs
parentFear the lockless LLUDP implementation! (diff)
downloadopensim-SC_OLD-56a27c37d3e84495988e423be7b52007cea595cc.zip
opensim-SC_OLD-56a27c37d3e84495988e423be7b52007cea595cc.tar.gz
opensim-SC_OLD-56a27c37d3e84495988e423be7b52007cea595cc.tar.bz2
opensim-SC_OLD-56a27c37d3e84495988e423be7b52007cea595cc.tar.xz
Simplified LLUDPClientCollection from three collections down to one. This will prevent any potential problems from inconsistency between the internal collections
Diffstat (limited to 'OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs')
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs75
1 files changed, 11 insertions, 64 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs
index 06fa3e2..abf3882 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs
@@ -40,14 +40,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
40 { 40 {
41 #region IComparers 41 #region IComparers
42 42
43 private sealed class UUIDComparer : IComparer<UUID>
44 {
45 public int Compare(UUID x, UUID y)
46 {
47 return x.Guid.CompareTo(y.Guid);
48 }
49 }
50
51 private sealed class IPEndPointComparer : IComparer<IPEndPoint> 43 private sealed class IPEndPointComparer : IComparer<IPEndPoint>
52 { 44 {
53 public int Compare(IPEndPoint x, IPEndPoint y) 45 public int Compare(IPEndPoint x, IPEndPoint y)
@@ -60,91 +52,46 @@ namespace OpenSim.Region.ClientStack.LindenUDP
60 52
61 #endregion IComparers 53 #endregion IComparers
62 54
63 private ImmutableMap<UUID, LLUDPClient> m_dict1; 55 private ImmutableMap<IPEndPoint, LLUDPClient> m_dict;
64 private ImmutableMap<IPEndPoint, LLUDPClient> m_dict2;
65 private LLUDPClient[] m_array;
66 56
67 public UDPClientCollection() 57 public UDPClientCollection()
68 { 58 {
69 m_dict1 = new ImmutableMap<UUID, LLUDPClient>(new UUIDComparer()); 59 m_dict = new ImmutableMap<IPEndPoint, LLUDPClient>(new IPEndPointComparer());
70 m_dict2 = new ImmutableMap<IPEndPoint, LLUDPClient>(new IPEndPointComparer());
71 m_array = new LLUDPClient[0];
72 } 60 }
73 61
74 public void Add(UUID key1, IPEndPoint key2, LLUDPClient value) 62 public void Add(IPEndPoint key, LLUDPClient value)
75 { 63 {
76 m_dict1 = m_dict1.Add(key1, value); 64 m_dict = m_dict.Add(key, value);
77 m_dict2 = m_dict2.Add(key2, value);
78
79 // Copy the array by hand
80 LLUDPClient[] oldArray = m_array;
81 int oldLength = oldArray.Length;
82 LLUDPClient[] newArray = new LLUDPClient[oldLength + 1];
83
84 for (int i = 0; i < oldLength; i++)
85 newArray[i] = oldArray[i];
86 newArray[oldLength] = value;
87
88 m_array = newArray;
89 } 65 }
90 66
91 public void Remove(UUID key1, IPEndPoint key2) 67 public void Remove(IPEndPoint key)
92 { 68 {
93 m_dict1 = m_dict1.Delete(key1); 69 m_dict = m_dict.Delete(key);
94 m_dict2 = m_dict2.Delete(key2);
95
96 LLUDPClient[] oldArray = m_array;
97 int oldLength = oldArray.Length;
98
99 // Copy the array by hand
100
101 LLUDPClient[] newArray = new LLUDPClient[oldLength - 1];
102 int j = 0;
103
104 for (int i = 0; i < oldLength; i++)
105 {
106 if (oldArray[i].AgentID != key1)
107 newArray[j++] = oldArray[i];
108 }
109
110 m_array = newArray;
111 } 70 }
112 71
113 public void Clear() 72 public void Clear()
114 { 73 {
115 m_dict1 = new ImmutableMap<UUID, LLUDPClient>(new UUIDComparer()); 74 m_dict = new ImmutableMap<IPEndPoint, LLUDPClient>(new IPEndPointComparer());
116 m_dict2 = new ImmutableMap<IPEndPoint, LLUDPClient>(new IPEndPointComparer());
117 m_array = new LLUDPClient[0];
118 } 75 }
119 76
120 public int Count 77 public int Count
121 { 78 {
122 get { return m_array.Length; } 79 get { return m_dict.Count; }
123 }
124
125 public bool ContainsKey(UUID key)
126 {
127 return m_dict1.ContainsKey(key);
128 } 80 }
129 81
130 public bool ContainsKey(IPEndPoint key) 82 public bool ContainsKey(IPEndPoint key)
131 { 83 {
132 return m_dict2.ContainsKey(key); 84 return m_dict.ContainsKey(key);
133 }
134
135 public bool TryGetValue(UUID key, out LLUDPClient value)
136 {
137 return m_dict1.TryGetValue(key, out value);
138 } 85 }
139 86
140 public bool TryGetValue(IPEndPoint key, out LLUDPClient value) 87 public bool TryGetValue(IPEndPoint key, out LLUDPClient value)
141 { 88 {
142 return m_dict2.TryGetValue(key, out value); 89 return m_dict.TryGetValue(key, out value);
143 } 90 }
144 91
145 public void ForEach(Action<LLUDPClient> action) 92 public void ForEach(Action<LLUDPClient> action)
146 { 93 {
147 Parallel.ForEach<LLUDPClient>(m_array, action); 94 Parallel.ForEach<LLUDPClient>(m_dict.Values, action);
148 } 95 }
149 } 96 }
150} 97}