more changes on scenegraph etc

0.9.1.0-post-fixes
UbitUmarov 2019-01-06 20:10:43 +00:00
parent 6e60917522
commit 950b605b42
4 changed files with 476 additions and 473 deletions

View File

@ -42,8 +42,6 @@ namespace OpenSim.Framework
Dictionary<TKey1, TValue> Dictionary1; Dictionary<TKey1, TValue> Dictionary1;
Dictionary<TKey2, TValue> Dictionary2; Dictionary<TKey2, TValue> Dictionary2;
private TValue[] m_array; private TValue[] m_array;
private int m_lastArrayVersion;
private int m_arrayVersion;
ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim(); ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim();
@ -51,22 +49,20 @@ namespace OpenSim.Framework
{ {
Dictionary1 = new Dictionary<TKey1,TValue>(); Dictionary1 = new Dictionary<TKey1,TValue>();
Dictionary2 = new Dictionary<TKey2,TValue>(); Dictionary2 = new Dictionary<TKey2,TValue>();
m_array = new TValue[0]; m_array = null;
m_lastArrayVersion = 0;
m_arrayVersion = 0;
} }
public DoubleDictionaryThreadAbortSafe(int capacity) public DoubleDictionaryThreadAbortSafe(int capacity)
{ {
Dictionary1 = new Dictionary<TKey1, TValue>(capacity); Dictionary1 = new Dictionary<TKey1, TValue>(capacity);
Dictionary2 = new Dictionary<TKey2, TValue>(capacity); Dictionary2 = new Dictionary<TKey2, TValue>(capacity);
m_lastArrayVersion = 0; m_array = null;
m_arrayVersion = 0;
} }
~DoubleDictionaryThreadAbortSafe() ~DoubleDictionaryThreadAbortSafe()
{ {
rwLock.Dispose(); if(rwLock != null)
rwLock.Dispose();
} }
public void Add(TKey1 key1, TKey2 key2, TValue value) public void Add(TKey1 key1, TKey2 key2, TValue value)
@ -83,6 +79,8 @@ namespace OpenSim.Framework
{ {
rwLock.EnterWriteLock(); rwLock.EnterWriteLock();
gotLock = true; gotLock = true;
}
/*
if (Dictionary1.ContainsKey(key1)) if (Dictionary1.ContainsKey(key1))
{ {
if (!Dictionary2.ContainsKey(key2)) if (!Dictionary2.ContainsKey(key2))
@ -93,10 +91,10 @@ namespace OpenSim.Framework
if (!Dictionary1.ContainsKey(key1)) if (!Dictionary1.ContainsKey(key1))
throw new ArgumentException("key2 exists in the dictionary but not key1"); throw new ArgumentException("key2 exists in the dictionary but not key1");
} }
*/
Dictionary1[key1] = value; Dictionary1[key1] = value;
Dictionary2[key2] = value; Dictionary2[key2] = value;
++m_arrayVersion; m_array = null;
}
} }
finally finally
{ {
@ -120,10 +118,10 @@ namespace OpenSim.Framework
{ {
rwLock.EnterWriteLock(); rwLock.EnterWriteLock();
gotLock = true; gotLock = true;
Dictionary1.Remove(key1);
success = Dictionary2.Remove(key2);
++m_arrayVersion;
} }
success = Dictionary1.Remove(key1);
success &= Dictionary2.Remove(key2);
m_array = null;
} }
finally finally
{ {
@ -164,7 +162,7 @@ namespace OpenSim.Framework
{ {
Dictionary1.Remove(key1); Dictionary1.Remove(key1);
Dictionary2.Remove(kvp.Key); Dictionary2.Remove(kvp.Key);
++m_arrayVersion; m_array = null;
} }
found = true; found = true;
break; break;
@ -211,7 +209,7 @@ namespace OpenSim.Framework
{ {
Dictionary2.Remove(key2); Dictionary2.Remove(key2);
Dictionary1.Remove(kvp.Key); Dictionary1.Remove(kvp.Key);
++m_arrayVersion; m_array = null;
} }
found = true; found = true;
break; break;
@ -244,9 +242,7 @@ namespace OpenSim.Framework
gotLock = true; gotLock = true;
Dictionary1.Clear(); Dictionary1.Clear();
Dictionary2.Clear(); Dictionary2.Clear();
m_array = new TValue[0]; m_array = null;
m_arrayVersion = 0;
m_lastArrayVersion = 0;
} }
} }
finally finally
@ -391,30 +387,12 @@ namespace OpenSim.Framework
public TValue FindValue(Predicate<TValue> predicate) public TValue FindValue(Predicate<TValue> predicate)
{ {
bool gotLock = false; TValue[] values = GetArray();
int len = values.Length;
try for (int i = 0; i < len; ++i)
{ {
// Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing if (predicate(values[i]))
// the acquision inside the main try. The inner finally block is needed because thread aborts cannot return values[i];
// interrupt code in these blocks (hence gotLock is guaranteed to be set correctly).
try {}
finally
{
rwLock.EnterReadLock();
gotLock = true;
}
foreach (TValue value in Dictionary1.Values)
{
if (predicate(value))
return value;
}
}
finally
{
if (gotLock)
rwLock.ExitReadLock();
} }
return default(TValue); return default(TValue);
@ -423,32 +401,14 @@ namespace OpenSim.Framework
public IList<TValue> FindAll(Predicate<TValue> predicate) public IList<TValue> FindAll(Predicate<TValue> predicate)
{ {
IList<TValue> list = new List<TValue>(); IList<TValue> list = new List<TValue>();
bool gotLock = false; TValue[] values = GetArray();
try int len = values.Length;
for (int i = 0; i < len; ++i)
{ {
// Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing if (predicate(values[i]))
// the acquision inside the main try. The inner finally block is needed because thread aborts cannot list.Add(values[i]);
// interrupt code in these blocks (hence gotLock is guaranteed to be set correctly).
try {}
finally
{
rwLock.EnterReadLock();
gotLock = true;
}
foreach (TValue value in Dictionary1.Values)
{
if (predicate(value))
list.Add(value);
}
} }
finally
{
if (gotLock)
rwLock.ExitReadLock();
}
return list; return list;
} }
@ -497,7 +457,7 @@ namespace OpenSim.Framework
for (int i = 0; i < list2.Count; i++) for (int i = 0; i < list2.Count; i++)
Dictionary2.Remove(list2[i]); Dictionary2.Remove(list2[i]);
++m_arrayVersion; m_array = null;
} }
} }
finally finally
@ -527,12 +487,10 @@ namespace OpenSim.Framework
rwLock.EnterWriteLock(); rwLock.EnterWriteLock();
gotLock = true; gotLock = true;
if (m_lastArrayVersion != m_arrayVersion) if (m_array == null)
{ {
TValue[] array = new TValue[Dictionary1.Count]; m_array = new TValue[Dictionary1.Count];
Dictionary1.Values.CopyTo(array, 0); Dictionary1.Values.CopyTo(m_array, 0);
m_array = array;
m_lastArrayVersion = m_arrayVersion;
} }
ret = m_array; ret = m_array;
} }

View File

@ -41,8 +41,6 @@ namespace OpenSim.Framework
{ {
private Dictionary<TKey, TValue> m_dict; private Dictionary<TKey, TValue> m_dict;
private TValue[] m_array; private TValue[] m_array;
private int m_lastArrayVersion;
private int m_arrayVersion;
/// <summary>Number of values currently stored in the collection</summary> /// <summary>Number of values currently stored in the collection</summary>
public int Count { get { return m_dict.Count; } } public int Count { get { return m_dict.Count; } }
@ -59,9 +57,7 @@ namespace OpenSim.Framework
public MapAndArray() public MapAndArray()
{ {
m_dict = new Dictionary<TKey, TValue>(); m_dict = new Dictionary<TKey, TValue>();
m_array = new TValue[0]; m_array = null;
m_lastArrayVersion = 0;
m_arrayVersion = 0;
} }
/// <summary> /// <summary>
@ -71,9 +67,7 @@ namespace OpenSim.Framework
public MapAndArray(int capacity) public MapAndArray(int capacity)
{ {
m_dict = new Dictionary<TKey, TValue>(capacity); m_dict = new Dictionary<TKey, TValue>(capacity);
m_array = new TValue[0]; m_array = null;
m_lastArrayVersion = 0;
m_arrayVersion = 0;
} }
/// <summary> /// <summary>
@ -91,7 +85,7 @@ namespace OpenSim.Framework
bool containedKey = m_dict.ContainsKey(key); bool containedKey = m_dict.ContainsKey(key);
m_dict[key] = value; m_dict[key] = value;
++m_arrayVersion; m_array = null;
return !containedKey; return !containedKey;
} }
@ -109,7 +103,7 @@ namespace OpenSim.Framework
lock (m_syncRoot) lock (m_syncRoot)
{ {
m_dict.Add(key, value); m_dict.Add(key, value);
++m_arrayVersion; m_array = null;
return m_dict.Count; return m_dict.Count;
} }
} }
@ -124,7 +118,7 @@ namespace OpenSim.Framework
lock (m_syncRoot) lock (m_syncRoot)
{ {
bool removed = m_dict.Remove(key); bool removed = m_dict.Remove(key);
++m_arrayVersion; m_array = null;
return removed; return removed;
} }
} }
@ -163,9 +157,7 @@ namespace OpenSim.Framework
lock (m_syncRoot) lock (m_syncRoot)
{ {
m_dict = new Dictionary<TKey, TValue>(); m_dict = new Dictionary<TKey, TValue>();
m_array = new TValue[0]; m_array = null;
m_lastArrayVersion = 0;
m_arrayVersion = 0;
} }
} }
@ -179,12 +171,10 @@ namespace OpenSim.Framework
{ {
lock (m_syncRoot) lock (m_syncRoot)
{ {
if(m_lastArrayVersion != m_arrayVersion) if (m_array == null)
{ {
TValue[] array = new TValue[m_dict.Count]; m_array = new TValue[m_dict.Count];
m_dict.Values.CopyTo(array, 0); m_dict.Values.CopyTo(m_array, 0);
m_array = array;
m_lastArrayVersion = m_arrayVersion;
} }
return m_array; return m_array;
} }

View File

@ -2796,12 +2796,6 @@ namespace OpenSim.Region.Framework.Scenes
return false; return false;
} }
public void updateScenePartGroup(SceneObjectPart part, SceneObjectGroup grp)
{
m_sceneGraph.updateScenePartGroup(part, grp);
}
/* not in use, outdate by async method /* not in use, outdate by async method
/// <summary> /// <summary>
/// Move the given scene object into a new region depending on which region its absolute position has moved /// Move the given scene object into a new region depending on which region its absolute position has moved
@ -5065,16 +5059,6 @@ Label_GroupsDone:
#region SceneGraph wrapper methods #region SceneGraph wrapper methods
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <returns></returns>
public UUID ConvertLocalIDToFullID(uint localID)
{
return m_sceneGraph.ConvertLocalIDToFullID(localID);
}
public void SwapRootAgentCount(bool rootChildChildRootTF) public void SwapRootAgentCount(bool rootChildChildRootTF)
{ {
m_sceneGraph.SwapRootChildAgent(rootChildChildRootTF); m_sceneGraph.SwapRootChildAgent(rootChildChildRootTF);

File diff suppressed because it is too large Load Diff