aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/ClientManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/ClientManager.cs')
-rw-r--r--OpenSim/Framework/ClientManager.cs65
1 files changed, 42 insertions, 23 deletions
diff --git a/OpenSim/Framework/ClientManager.cs b/OpenSim/Framework/ClientManager.cs
index 45c54e4..1508c7f 100644
--- a/OpenSim/Framework/ClientManager.cs
+++ b/OpenSim/Framework/ClientManager.cs
@@ -51,7 +51,14 @@ namespace OpenSim.Framework
51 private object m_syncRoot = new object(); 51 private object m_syncRoot = new object();
52 52
53 /// <summary>Number of clients in the collection</summary> 53 /// <summary>Number of clients in the collection</summary>
54 public int Count { get { return m_dict1.Count; } } 54 public int Count
55 {
56 get
57 {
58 lock (m_syncRoot)
59 return m_dict1.Count;
60 }
61 }
55 62
56 /// <summary> 63 /// <summary>
57 /// Default constructor 64 /// Default constructor
@@ -60,7 +67,7 @@ namespace OpenSim.Framework
60 { 67 {
61 m_dict1 = new Dictionary<UUID, IClientAPI>(); 68 m_dict1 = new Dictionary<UUID, IClientAPI>();
62 m_dict2 = new Dictionary<IPEndPoint, IClientAPI>(); 69 m_dict2 = new Dictionary<IPEndPoint, IClientAPI>();
63 m_array = new IClientAPI[0]; 70 m_array = null;
64 } 71 }
65 72
66 /// <summary> 73 /// <summary>
@@ -74,17 +81,9 @@ namespace OpenSim.Framework
74 { 81 {
75 lock (m_syncRoot) 82 lock (m_syncRoot)
76 { 83 {
77 // allow self healing
78// if (m_dict1.ContainsKey(value.AgentId) || m_dict2.ContainsKey(value.RemoteEndPoint))
79// return false;
80
81 m_dict1[value.AgentId] = value; 84 m_dict1[value.AgentId] = value;
82 m_dict2[value.RemoteEndPoint] = value; 85 m_dict2[value.RemoteEndPoint] = value;
83 86 m_array = null;
84 // dict1 is the master
85 IClientAPI[] newArray = new IClientAPI[m_dict1.Count];
86 m_dict1.Values.CopyTo(newArray, 0);
87 m_array = newArray;
88 } 87 }
89 88
90 return true; 89 return true;
@@ -105,10 +104,7 @@ namespace OpenSim.Framework
105 { 104 {
106 m_dict1.Remove(key); 105 m_dict1.Remove(key);
107 m_dict2.Remove(value.RemoteEndPoint); 106 m_dict2.Remove(value.RemoteEndPoint);
108 107 m_array = null;
109 IClientAPI[] newArray = new IClientAPI[m_dict1.Count];
110 m_dict1.Values.CopyTo(newArray, 0);
111 m_array = newArray;
112 return true; 108 return true;
113 } 109 }
114 } 110 }
@@ -124,7 +120,7 @@ namespace OpenSim.Framework
124 { 120 {
125 m_dict1.Clear(); 121 m_dict1.Clear();
126 m_dict2.Clear(); 122 m_dict2.Clear();
127 m_array = new IClientAPI[0]; 123 m_array = null;
128 } 124 }
129 } 125 }
130 126
@@ -135,7 +131,8 @@ namespace OpenSim.Framework
135 /// <returns>True if the UUID was found in the collection, otherwise false</returns> 131 /// <returns>True if the UUID was found in the collection, otherwise false</returns>
136 public bool ContainsKey(UUID key) 132 public bool ContainsKey(UUID key)
137 { 133 {
138 return m_dict1.ContainsKey(key); 134 lock (m_syncRoot)
135 return m_dict1.ContainsKey(key);
139 } 136 }
140 137
141 /// <summary> 138 /// <summary>
@@ -145,7 +142,8 @@ namespace OpenSim.Framework
145 /// <returns>True if the endpoint was found in the collection, otherwise false</returns> 142 /// <returns>True if the endpoint was found in the collection, otherwise false</returns>
146 public bool ContainsKey(IPEndPoint key) 143 public bool ContainsKey(IPEndPoint key)
147 { 144 {
148 return m_dict2.ContainsKey(key); 145 lock (m_syncRoot)
146 return m_dict2.ContainsKey(key);
149 } 147 }
150 148
151 /// <summary> 149 /// <summary>
@@ -156,8 +154,12 @@ namespace OpenSim.Framework
156 /// <returns>True if the lookup succeeded, otherwise false</returns> 154 /// <returns>True if the lookup succeeded, otherwise false</returns>
157 public bool TryGetValue(UUID key, out IClientAPI value) 155 public bool TryGetValue(UUID key, out IClientAPI value)
158 { 156 {
159 try { return m_dict1.TryGetValue(key, out value); } 157 try
160 catch (Exception) 158 {
159 lock (m_syncRoot)
160 return m_dict1.TryGetValue(key, out value);
161 }
162 catch
161 { 163 {
162 value = null; 164 value = null;
163 return false; 165 return false;
@@ -172,8 +174,12 @@ namespace OpenSim.Framework
172 /// <returns>True if the lookup succeeded, otherwise false</returns> 174 /// <returns>True if the lookup succeeded, otherwise false</returns>
173 public bool TryGetValue(IPEndPoint key, out IClientAPI value) 175 public bool TryGetValue(IPEndPoint key, out IClientAPI value)
174 { 176 {
175 try { return m_dict2.TryGetValue(key, out value); } 177 try
176 catch (Exception) 178 {
179 lock (m_syncRoot)
180 return m_dict2.TryGetValue(key, out value);
181 }
182 catch
177 { 183 {
178 value = null; 184 value = null;
179 return false; 185 return false;
@@ -187,7 +193,20 @@ namespace OpenSim.Framework
187 /// <param name="action">Action to perform on each element</param> 193 /// <param name="action">Action to perform on each element</param>
188 public void ForEach(Action<IClientAPI> action) 194 public void ForEach(Action<IClientAPI> action)
189 { 195 {
190 IClientAPI[] localArray = m_array; 196 IClientAPI[] localArray;
197 lock (m_syncRoot)
198 {
199 if (m_array == null)
200 {
201 if (m_dict1.Count == 0)
202 return;
203
204 m_array = new IClientAPI[m_dict1.Count];
205 m_dict1.Values.CopyTo(m_array, 0);
206 }
207 localArray = m_array;
208 }
209
191 for (int i = 0; i < localArray.Length; i++) 210 for (int i = 0; i < localArray.Length; i++)
192 action(localArray[i]); 211 action(localArray[i]);
193 } 212 }