From 54b4523da85554dfeff9369ec8b7bfc438953dcc Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 6 Jan 2019 02:10:17 +0000 Subject: let DoubleDictionary... also have a values array --- .../Framework/DoubleDictionaryThreadAbortSafe.cs | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/DoubleDictionaryThreadAbortSafe.cs b/OpenSim/Framework/DoubleDictionaryThreadAbortSafe.cs index 816523b..e4c85e4 100644 --- a/OpenSim/Framework/DoubleDictionaryThreadAbortSafe.cs +++ b/OpenSim/Framework/DoubleDictionaryThreadAbortSafe.cs @@ -41,18 +41,27 @@ namespace OpenSim.Framework { Dictionary Dictionary1; Dictionary Dictionary2; + private TValue[] m_array; + private int m_lastArrayVersion; + private int m_arrayVersion; + ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim(); public DoubleDictionaryThreadAbortSafe() { Dictionary1 = new Dictionary(); Dictionary2 = new Dictionary(); + m_array = new TValue[0]; + m_lastArrayVersion = 0; + m_arrayVersion = 0; } public DoubleDictionaryThreadAbortSafe(int capacity) { Dictionary1 = new Dictionary(capacity); Dictionary2 = new Dictionary(capacity); + m_lastArrayVersion = 0; + m_arrayVersion = 0; } ~DoubleDictionaryThreadAbortSafe() @@ -86,6 +95,7 @@ namespace OpenSim.Framework } Dictionary1[key1] = value; Dictionary2[key2] = value; + ++m_arrayVersion; } } finally @@ -112,6 +122,7 @@ namespace OpenSim.Framework gotLock = true; Dictionary1.Remove(key1); success = Dictionary2.Remove(key2); + ++m_arrayVersion; } } finally @@ -153,6 +164,7 @@ namespace OpenSim.Framework { Dictionary1.Remove(key1); Dictionary2.Remove(kvp.Key); + ++m_arrayVersion; } found = true; break; @@ -199,6 +211,7 @@ namespace OpenSim.Framework { Dictionary2.Remove(key2); Dictionary1.Remove(kvp.Key); + ++m_arrayVersion; } found = true; break; @@ -231,6 +244,9 @@ namespace OpenSim.Framework gotLock = true; Dictionary1.Clear(); Dictionary2.Clear(); + m_array = new TValue[0]; + m_arrayVersion = 0; + m_lastArrayVersion = 0; } } finally @@ -497,6 +513,7 @@ namespace OpenSim.Framework for (int i = 0; i < list2.Count; i++) Dictionary2.Remove(list2[i]); + ++m_arrayVersion; } } finally @@ -513,5 +530,35 @@ namespace OpenSim.Framework return list.Count; } + + public TValue[] GetArray() + { + TValue[] ret = new TValue[0]; + bool gotLock = false; + try + { + try { } + finally + { + rwLock.EnterWriteLock(); + gotLock = true; + + if (m_lastArrayVersion != m_arrayVersion) + { + TValue[] array = new TValue[Dictionary1.Count]; + Dictionary1.Values.CopyTo(array, 0); + m_array = array; + m_lastArrayVersion = m_arrayVersion; + } + ret = m_array; + } + } + finally + { + if (gotLock) + rwLock.ExitWriteLock(); + } + return ret; + } } } \ No newline at end of file -- cgit v1.1