(almost) useless change

0.9.1.0-post-fixes
UbitUmarov 2019-02-15 02:08:45 +00:00
parent b242232c7b
commit 040ab65f68
1 changed files with 42 additions and 23 deletions

View File

@ -51,7 +51,14 @@ namespace OpenSim.Framework
private object m_syncRoot = new object();
/// <summary>Number of clients in the collection</summary>
public int Count { get { return m_dict1.Count; } }
public int Count
{
get
{
lock (m_syncRoot)
return m_dict1.Count;
}
}
/// <summary>
/// Default constructor
@ -60,7 +67,7 @@ namespace OpenSim.Framework
{
m_dict1 = new Dictionary<UUID, IClientAPI>();
m_dict2 = new Dictionary<IPEndPoint, IClientAPI>();
m_array = new IClientAPI[0];
m_array = null;
}
/// <summary>
@ -74,17 +81,9 @@ namespace OpenSim.Framework
{
lock (m_syncRoot)
{
// allow self healing
// if (m_dict1.ContainsKey(value.AgentId) || m_dict2.ContainsKey(value.RemoteEndPoint))
// return false;
m_dict1[value.AgentId] = value;
m_dict2[value.RemoteEndPoint] = value;
// dict1 is the master
IClientAPI[] newArray = new IClientAPI[m_dict1.Count];
m_dict1.Values.CopyTo(newArray, 0);
m_array = newArray;
m_array = null;
}
return true;
@ -105,10 +104,7 @@ namespace OpenSim.Framework
{
m_dict1.Remove(key);
m_dict2.Remove(value.RemoteEndPoint);
IClientAPI[] newArray = new IClientAPI[m_dict1.Count];
m_dict1.Values.CopyTo(newArray, 0);
m_array = newArray;
m_array = null;
return true;
}
}
@ -124,7 +120,7 @@ namespace OpenSim.Framework
{
m_dict1.Clear();
m_dict2.Clear();
m_array = new IClientAPI[0];
m_array = null;
}
}
@ -135,7 +131,8 @@ namespace OpenSim.Framework
/// <returns>True if the UUID was found in the collection, otherwise false</returns>
public bool ContainsKey(UUID key)
{
return m_dict1.ContainsKey(key);
lock (m_syncRoot)
return m_dict1.ContainsKey(key);
}
/// <summary>
@ -145,7 +142,8 @@ namespace OpenSim.Framework
/// <returns>True if the endpoint was found in the collection, otherwise false</returns>
public bool ContainsKey(IPEndPoint key)
{
return m_dict2.ContainsKey(key);
lock (m_syncRoot)
return m_dict2.ContainsKey(key);
}
/// <summary>
@ -156,8 +154,12 @@ namespace OpenSim.Framework
/// <returns>True if the lookup succeeded, otherwise false</returns>
public bool TryGetValue(UUID key, out IClientAPI value)
{
try { return m_dict1.TryGetValue(key, out value); }
catch (Exception)
try
{
lock (m_syncRoot)
return m_dict1.TryGetValue(key, out value);
}
catch
{
value = null;
return false;
@ -172,8 +174,12 @@ namespace OpenSim.Framework
/// <returns>True if the lookup succeeded, otherwise false</returns>
public bool TryGetValue(IPEndPoint key, out IClientAPI value)
{
try { return m_dict2.TryGetValue(key, out value); }
catch (Exception)
try
{
lock (m_syncRoot)
return m_dict2.TryGetValue(key, out value);
}
catch
{
value = null;
return false;
@ -187,7 +193,20 @@ namespace OpenSim.Framework
/// <param name="action">Action to perform on each element</param>
public void ForEach(Action<IClientAPI> action)
{
IClientAPI[] localArray = m_array;
IClientAPI[] localArray;
lock (m_syncRoot)
{
if (m_array == null)
{
if (m_dict1.Count == 0)
return;
m_array = new IClientAPI[m_dict1.Count];
m_dict1.Values.CopyTo(m_array, 0);
}
localArray = m_array;
}
for (int i = 0; i < localArray.Length; i++)
action(localArray[i]);
}