diff options
-rw-r--r-- | OpenSim/Framework/DoubleDictionaryThreadAbortSafe.cs | 47 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/EntityManager.cs | 4 |
2 files changed, 48 insertions, 3 deletions
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 | |||
41 | { | 41 | { |
42 | Dictionary<TKey1, TValue> Dictionary1; | 42 | Dictionary<TKey1, TValue> Dictionary1; |
43 | Dictionary<TKey2, TValue> Dictionary2; | 43 | Dictionary<TKey2, TValue> Dictionary2; |
44 | private TValue[] m_array; | ||
45 | private int m_lastArrayVersion; | ||
46 | private int m_arrayVersion; | ||
47 | |||
44 | ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim(); | 48 | ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim(); |
45 | 49 | ||
46 | public DoubleDictionaryThreadAbortSafe() | 50 | public DoubleDictionaryThreadAbortSafe() |
47 | { | 51 | { |
48 | Dictionary1 = new Dictionary<TKey1,TValue>(); | 52 | Dictionary1 = new Dictionary<TKey1,TValue>(); |
49 | Dictionary2 = new Dictionary<TKey2,TValue>(); | 53 | Dictionary2 = new Dictionary<TKey2,TValue>(); |
54 | m_array = new TValue[0]; | ||
55 | m_lastArrayVersion = 0; | ||
56 | m_arrayVersion = 0; | ||
50 | } | 57 | } |
51 | 58 | ||
52 | public DoubleDictionaryThreadAbortSafe(int capacity) | 59 | public DoubleDictionaryThreadAbortSafe(int capacity) |
53 | { | 60 | { |
54 | Dictionary1 = new Dictionary<TKey1, TValue>(capacity); | 61 | Dictionary1 = new Dictionary<TKey1, TValue>(capacity); |
55 | Dictionary2 = new Dictionary<TKey2, TValue>(capacity); | 62 | Dictionary2 = new Dictionary<TKey2, TValue>(capacity); |
63 | m_lastArrayVersion = 0; | ||
64 | m_arrayVersion = 0; | ||
56 | } | 65 | } |
57 | 66 | ||
58 | ~DoubleDictionaryThreadAbortSafe() | 67 | ~DoubleDictionaryThreadAbortSafe() |
@@ -86,6 +95,7 @@ namespace OpenSim.Framework | |||
86 | } | 95 | } |
87 | Dictionary1[key1] = value; | 96 | Dictionary1[key1] = value; |
88 | Dictionary2[key2] = value; | 97 | Dictionary2[key2] = value; |
98 | ++m_arrayVersion; | ||
89 | } | 99 | } |
90 | } | 100 | } |
91 | finally | 101 | finally |
@@ -112,6 +122,7 @@ namespace OpenSim.Framework | |||
112 | gotLock = true; | 122 | gotLock = true; |
113 | Dictionary1.Remove(key1); | 123 | Dictionary1.Remove(key1); |
114 | success = Dictionary2.Remove(key2); | 124 | success = Dictionary2.Remove(key2); |
125 | ++m_arrayVersion; | ||
115 | } | 126 | } |
116 | } | 127 | } |
117 | finally | 128 | finally |
@@ -153,6 +164,7 @@ namespace OpenSim.Framework | |||
153 | { | 164 | { |
154 | Dictionary1.Remove(key1); | 165 | Dictionary1.Remove(key1); |
155 | Dictionary2.Remove(kvp.Key); | 166 | Dictionary2.Remove(kvp.Key); |
167 | ++m_arrayVersion; | ||
156 | } | 168 | } |
157 | found = true; | 169 | found = true; |
158 | break; | 170 | break; |
@@ -199,6 +211,7 @@ namespace OpenSim.Framework | |||
199 | { | 211 | { |
200 | Dictionary2.Remove(key2); | 212 | Dictionary2.Remove(key2); |
201 | Dictionary1.Remove(kvp.Key); | 213 | Dictionary1.Remove(kvp.Key); |
214 | ++m_arrayVersion; | ||
202 | } | 215 | } |
203 | found = true; | 216 | found = true; |
204 | break; | 217 | break; |
@@ -231,6 +244,9 @@ namespace OpenSim.Framework | |||
231 | gotLock = true; | 244 | gotLock = true; |
232 | Dictionary1.Clear(); | 245 | Dictionary1.Clear(); |
233 | Dictionary2.Clear(); | 246 | Dictionary2.Clear(); |
247 | m_array = new TValue[0]; | ||
248 | m_arrayVersion = 0; | ||
249 | m_lastArrayVersion = 0; | ||
234 | } | 250 | } |
235 | } | 251 | } |
236 | finally | 252 | finally |
@@ -497,6 +513,7 @@ namespace OpenSim.Framework | |||
497 | 513 | ||
498 | for (int i = 0; i < list2.Count; i++) | 514 | for (int i = 0; i < list2.Count; i++) |
499 | Dictionary2.Remove(list2[i]); | 515 | Dictionary2.Remove(list2[i]); |
516 | ++m_arrayVersion; | ||
500 | } | 517 | } |
501 | } | 518 | } |
502 | finally | 519 | finally |
@@ -513,5 +530,35 @@ namespace OpenSim.Framework | |||
513 | 530 | ||
514 | return list.Count; | 531 | return list.Count; |
515 | } | 532 | } |
533 | |||
534 | public TValue[] GetArray() | ||
535 | { | ||
536 | TValue[] ret = new TValue[0]; | ||
537 | bool gotLock = false; | ||
538 | try | ||
539 | { | ||
540 | try { } | ||
541 | finally | ||
542 | { | ||
543 | rwLock.EnterWriteLock(); | ||
544 | gotLock = true; | ||
545 | |||
546 | if (m_lastArrayVersion != m_arrayVersion) | ||
547 | { | ||
548 | TValue[] array = new TValue[Dictionary1.Count]; | ||
549 | Dictionary1.Values.CopyTo(array, 0); | ||
550 | m_array = array; | ||
551 | m_lastArrayVersion = m_arrayVersion; | ||
552 | } | ||
553 | ret = m_array; | ||
554 | } | ||
555 | } | ||
556 | finally | ||
557 | { | ||
558 | if (gotLock) | ||
559 | rwLock.ExitWriteLock(); | ||
560 | } | ||
561 | return ret; | ||
562 | } | ||
516 | } | 563 | } |
517 | } \ No newline at end of file | 564 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Framework/Scenes/EntityManager.cs b/OpenSim/Region/Framework/Scenes/EntityManager.cs index 4654efe..f034de8 100644 --- a/OpenSim/Region/Framework/Scenes/EntityManager.cs +++ b/OpenSim/Region/Framework/Scenes/EntityManager.cs | |||
@@ -94,9 +94,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
94 | 94 | ||
95 | public EntityBase[] GetEntities() | 95 | public EntityBase[] GetEntities() |
96 | { | 96 | { |
97 | List<EntityBase> tmp = new List<EntityBase>(m_entities.Count); | 97 | return m_entities.GetArray(); |
98 | ForEach(delegate(EntityBase entity) { tmp.Add(entity); }); | ||
99 | return tmp.ToArray(); | ||
100 | } | 98 | } |
101 | 99 | ||
102 | public void ForEach(Action<EntityBase> action) | 100 | public void ForEach(Action<EntityBase> action) |