From 040ab65f680583d4c73e9edb8004b60e1fe25e86 Mon Sep 17 00:00:00 2001
From: UbitUmarov
Date: Fri, 15 Feb 2019 02:08:45 +0000
Subject: (almost) useless change
---
OpenSim/Framework/ClientManager.cs | 65 ++++++++++++++++++++++++--------------
1 file 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
private object m_syncRoot = new object();
/// Number of clients in the collection
- public int Count { get { return m_dict1.Count; } }
+ public int Count
+ {
+ get
+ {
+ lock (m_syncRoot)
+ return m_dict1.Count;
+ }
+ }
///
/// Default constructor
@@ -60,7 +67,7 @@ namespace OpenSim.Framework
{
m_dict1 = new Dictionary();
m_dict2 = new Dictionary();
- m_array = new IClientAPI[0];
+ m_array = null;
}
///
@@ -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
/// True if the UUID was found in the collection, otherwise false
public bool ContainsKey(UUID key)
{
- return m_dict1.ContainsKey(key);
+ lock (m_syncRoot)
+ return m_dict1.ContainsKey(key);
}
///
@@ -145,7 +142,8 @@ namespace OpenSim.Framework
/// True if the endpoint was found in the collection, otherwise false
public bool ContainsKey(IPEndPoint key)
{
- return m_dict2.ContainsKey(key);
+ lock (m_syncRoot)
+ return m_dict2.ContainsKey(key);
}
///
@@ -156,8 +154,12 @@ namespace OpenSim.Framework
/// True if the lookup succeeded, otherwise false
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
/// True if the lookup succeeded, otherwise false
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
/// Action to perform on each element
public void ForEach(Action 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]);
}
--
cgit v1.1