aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorUbitUmarov2019-01-06 20:10:43 +0000
committerUbitUmarov2019-01-06 20:10:43 +0000
commit950b605b429e95ffef8a184ff0218a9d36ab608a (patch)
tree7d9260bae7792440969918c3ee511b25a81ec3c3 /OpenSim/Framework
parentchange its foreach (diff)
downloadopensim-SC-950b605b429e95ffef8a184ff0218a9d36ab608a.zip
opensim-SC-950b605b429e95ffef8a184ff0218a9d36ab608a.tar.gz
opensim-SC-950b605b429e95ffef8a184ff0218a9d36ab608a.tar.bz2
opensim-SC-950b605b429e95ffef8a184ff0218a9d36ab608a.tar.xz
more changes on scenegraph etc
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/DoubleDictionaryThreadAbortSafe.cs98
-rw-r--r--OpenSim/Framework/MapAndArray.cs28
2 files changed, 37 insertions, 89 deletions
diff --git a/OpenSim/Framework/DoubleDictionaryThreadAbortSafe.cs b/OpenSim/Framework/DoubleDictionaryThreadAbortSafe.cs
index 5b9a45c..73d0d20 100644
--- a/OpenSim/Framework/DoubleDictionaryThreadAbortSafe.cs
+++ b/OpenSim/Framework/DoubleDictionaryThreadAbortSafe.cs
@@ -42,8 +42,6 @@ namespace OpenSim.Framework
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; 44 private TValue[] m_array;
45 private int m_lastArrayVersion;
46 private int m_arrayVersion;
47 45
48 ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim(); 46 ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim();
49 47
@@ -51,22 +49,20 @@ namespace OpenSim.Framework
51 { 49 {
52 Dictionary1 = new Dictionary<TKey1,TValue>(); 50 Dictionary1 = new Dictionary<TKey1,TValue>();
53 Dictionary2 = new Dictionary<TKey2,TValue>(); 51 Dictionary2 = new Dictionary<TKey2,TValue>();
54 m_array = new TValue[0]; 52 m_array = null;
55 m_lastArrayVersion = 0;
56 m_arrayVersion = 0;
57 } 53 }
58 54
59 public DoubleDictionaryThreadAbortSafe(int capacity) 55 public DoubleDictionaryThreadAbortSafe(int capacity)
60 { 56 {
61 Dictionary1 = new Dictionary<TKey1, TValue>(capacity); 57 Dictionary1 = new Dictionary<TKey1, TValue>(capacity);
62 Dictionary2 = new Dictionary<TKey2, TValue>(capacity); 58 Dictionary2 = new Dictionary<TKey2, TValue>(capacity);
63 m_lastArrayVersion = 0; 59 m_array = null;
64 m_arrayVersion = 0;
65 } 60 }
66 61
67 ~DoubleDictionaryThreadAbortSafe() 62 ~DoubleDictionaryThreadAbortSafe()
68 { 63 {
69 rwLock.Dispose(); 64 if(rwLock != null)
65 rwLock.Dispose();
70 } 66 }
71 67
72 public void Add(TKey1 key1, TKey2 key2, TValue value) 68 public void Add(TKey1 key1, TKey2 key2, TValue value)
@@ -83,6 +79,8 @@ namespace OpenSim.Framework
83 { 79 {
84 rwLock.EnterWriteLock(); 80 rwLock.EnterWriteLock();
85 gotLock = true; 81 gotLock = true;
82 }
83/*
86 if (Dictionary1.ContainsKey(key1)) 84 if (Dictionary1.ContainsKey(key1))
87 { 85 {
88 if (!Dictionary2.ContainsKey(key2)) 86 if (!Dictionary2.ContainsKey(key2))
@@ -93,10 +91,10 @@ namespace OpenSim.Framework
93 if (!Dictionary1.ContainsKey(key1)) 91 if (!Dictionary1.ContainsKey(key1))
94 throw new ArgumentException("key2 exists in the dictionary but not key1"); 92 throw new ArgumentException("key2 exists in the dictionary but not key1");
95 } 93 }
94*/
96 Dictionary1[key1] = value; 95 Dictionary1[key1] = value;
97 Dictionary2[key2] = value; 96 Dictionary2[key2] = value;
98 ++m_arrayVersion; 97 m_array = null;
99 }
100 } 98 }
101 finally 99 finally
102 { 100 {
@@ -120,10 +118,10 @@ namespace OpenSim.Framework
120 { 118 {
121 rwLock.EnterWriteLock(); 119 rwLock.EnterWriteLock();
122 gotLock = true; 120 gotLock = true;
123 Dictionary1.Remove(key1);
124 success = Dictionary2.Remove(key2);
125 ++m_arrayVersion;
126 } 121 }
122 success = Dictionary1.Remove(key1);
123 success &= Dictionary2.Remove(key2);
124 m_array = null;
127 } 125 }
128 finally 126 finally
129 { 127 {
@@ -164,7 +162,7 @@ namespace OpenSim.Framework
164 { 162 {
165 Dictionary1.Remove(key1); 163 Dictionary1.Remove(key1);
166 Dictionary2.Remove(kvp.Key); 164 Dictionary2.Remove(kvp.Key);
167 ++m_arrayVersion; 165 m_array = null;
168 } 166 }
169 found = true; 167 found = true;
170 break; 168 break;
@@ -211,7 +209,7 @@ namespace OpenSim.Framework
211 { 209 {
212 Dictionary2.Remove(key2); 210 Dictionary2.Remove(key2);
213 Dictionary1.Remove(kvp.Key); 211 Dictionary1.Remove(kvp.Key);
214 ++m_arrayVersion; 212 m_array = null;
215 } 213 }
216 found = true; 214 found = true;
217 break; 215 break;
@@ -244,9 +242,7 @@ namespace OpenSim.Framework
244 gotLock = true; 242 gotLock = true;
245 Dictionary1.Clear(); 243 Dictionary1.Clear();
246 Dictionary2.Clear(); 244 Dictionary2.Clear();
247 m_array = new TValue[0]; 245 m_array = null;
248 m_arrayVersion = 0;
249 m_lastArrayVersion = 0;
250 } 246 }
251 } 247 }
252 finally 248 finally
@@ -391,30 +387,12 @@ namespace OpenSim.Framework
391 387
392 public TValue FindValue(Predicate<TValue> predicate) 388 public TValue FindValue(Predicate<TValue> predicate)
393 { 389 {
394 bool gotLock = false; 390 TValue[] values = GetArray();
395 391 int len = values.Length;
396 try 392 for (int i = 0; i < len; ++i)
397 { 393 {
398 // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing 394 if (predicate(values[i]))
399 // the acquision inside the main try. The inner finally block is needed because thread aborts cannot 395 return values[i];
400 // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly).
401 try {}
402 finally
403 {
404 rwLock.EnterReadLock();
405 gotLock = true;
406 }
407
408 foreach (TValue value in Dictionary1.Values)
409 {
410 if (predicate(value))
411 return value;
412 }
413 }
414 finally
415 {
416 if (gotLock)
417 rwLock.ExitReadLock();
418 } 396 }
419 397
420 return default(TValue); 398 return default(TValue);
@@ -423,32 +401,14 @@ namespace OpenSim.Framework
423 public IList<TValue> FindAll(Predicate<TValue> predicate) 401 public IList<TValue> FindAll(Predicate<TValue> predicate)
424 { 402 {
425 IList<TValue> list = new List<TValue>(); 403 IList<TValue> list = new List<TValue>();
426 bool gotLock = false; 404 TValue[] values = GetArray();
427
428 try
429 {
430 // Avoid an asynchronous Thread.Abort() from possibly never existing an acquired lock by placing
431 // the acquision inside the main try. The inner finally block is needed because thread aborts cannot
432 // interrupt code in these blocks (hence gotLock is guaranteed to be set correctly).
433 try {}
434 finally
435 {
436 rwLock.EnterReadLock();
437 gotLock = true;
438 }
439 405
440 foreach (TValue value in Dictionary1.Values) 406 int len = values.Length;
441 { 407 for (int i = 0; i < len; ++i)
442 if (predicate(value))
443 list.Add(value);
444 }
445 }
446 finally
447 { 408 {
448 if (gotLock) 409 if (predicate(values[i]))
449 rwLock.ExitReadLock(); 410 list.Add(values[i]);
450 } 411 }
451
452 return list; 412 return list;
453 } 413 }
454 414
@@ -497,7 +457,7 @@ namespace OpenSim.Framework
497 457
498 for (int i = 0; i < list2.Count; i++) 458 for (int i = 0; i < list2.Count; i++)
499 Dictionary2.Remove(list2[i]); 459 Dictionary2.Remove(list2[i]);
500 ++m_arrayVersion; 460 m_array = null;
501 } 461 }
502 } 462 }
503 finally 463 finally
@@ -527,12 +487,10 @@ namespace OpenSim.Framework
527 rwLock.EnterWriteLock(); 487 rwLock.EnterWriteLock();
528 gotLock = true; 488 gotLock = true;
529 489
530 if (m_lastArrayVersion != m_arrayVersion) 490 if (m_array == null)
531 { 491 {
532 TValue[] array = new TValue[Dictionary1.Count]; 492 m_array = new TValue[Dictionary1.Count];
533 Dictionary1.Values.CopyTo(array, 0); 493 Dictionary1.Values.CopyTo(m_array, 0);
534 m_array = array;
535 m_lastArrayVersion = m_arrayVersion;
536 } 494 }
537 ret = m_array; 495 ret = m_array;
538 } 496 }
diff --git a/OpenSim/Framework/MapAndArray.cs b/OpenSim/Framework/MapAndArray.cs
index a3ce55e..41874d0 100644
--- a/OpenSim/Framework/MapAndArray.cs
+++ b/OpenSim/Framework/MapAndArray.cs
@@ -41,8 +41,6 @@ namespace OpenSim.Framework
41 { 41 {
42 private Dictionary<TKey, TValue> m_dict; 42 private Dictionary<TKey, TValue> m_dict;
43 private TValue[] m_array; 43 private TValue[] m_array;
44 private int m_lastArrayVersion;
45 private int m_arrayVersion;
46 44
47 /// <summary>Number of values currently stored in the collection</summary> 45 /// <summary>Number of values currently stored in the collection</summary>
48 public int Count { get { return m_dict.Count; } } 46 public int Count { get { return m_dict.Count; } }
@@ -59,9 +57,7 @@ namespace OpenSim.Framework
59 public MapAndArray() 57 public MapAndArray()
60 { 58 {
61 m_dict = new Dictionary<TKey, TValue>(); 59 m_dict = new Dictionary<TKey, TValue>();
62 m_array = new TValue[0]; 60 m_array = null;
63 m_lastArrayVersion = 0;
64 m_arrayVersion = 0;
65 } 61 }
66 62
67 /// <summary> 63 /// <summary>
@@ -71,9 +67,7 @@ namespace OpenSim.Framework
71 public MapAndArray(int capacity) 67 public MapAndArray(int capacity)
72 { 68 {
73 m_dict = new Dictionary<TKey, TValue>(capacity); 69 m_dict = new Dictionary<TKey, TValue>(capacity);
74 m_array = new TValue[0]; 70 m_array = null;
75 m_lastArrayVersion = 0;
76 m_arrayVersion = 0;
77 } 71 }
78 72
79 /// <summary> 73 /// <summary>
@@ -91,7 +85,7 @@ namespace OpenSim.Framework
91 bool containedKey = m_dict.ContainsKey(key); 85 bool containedKey = m_dict.ContainsKey(key);
92 86
93 m_dict[key] = value; 87 m_dict[key] = value;
94 ++m_arrayVersion; 88 m_array = null;
95 89
96 return !containedKey; 90 return !containedKey;
97 } 91 }
@@ -109,7 +103,7 @@ namespace OpenSim.Framework
109 lock (m_syncRoot) 103 lock (m_syncRoot)
110 { 104 {
111 m_dict.Add(key, value); 105 m_dict.Add(key, value);
112 ++m_arrayVersion; 106 m_array = null;
113 return m_dict.Count; 107 return m_dict.Count;
114 } 108 }
115 } 109 }
@@ -124,7 +118,7 @@ namespace OpenSim.Framework
124 lock (m_syncRoot) 118 lock (m_syncRoot)
125 { 119 {
126 bool removed = m_dict.Remove(key); 120 bool removed = m_dict.Remove(key);
127 ++m_arrayVersion; 121 m_array = null;
128 return removed; 122 return removed;
129 } 123 }
130 } 124 }
@@ -163,9 +157,7 @@ namespace OpenSim.Framework
163 lock (m_syncRoot) 157 lock (m_syncRoot)
164 { 158 {
165 m_dict = new Dictionary<TKey, TValue>(); 159 m_dict = new Dictionary<TKey, TValue>();
166 m_array = new TValue[0]; 160 m_array = null;
167 m_lastArrayVersion = 0;
168 m_arrayVersion = 0;
169 } 161 }
170 } 162 }
171 163
@@ -179,12 +171,10 @@ namespace OpenSim.Framework
179 { 171 {
180 lock (m_syncRoot) 172 lock (m_syncRoot)
181 { 173 {
182 if(m_lastArrayVersion != m_arrayVersion) 174 if (m_array == null)
183 { 175 {
184 TValue[] array = new TValue[m_dict.Count]; 176 m_array = new TValue[m_dict.Count];
185 m_dict.Values.CopyTo(array, 0); 177 m_dict.Values.CopyTo(m_array, 0);
186 m_array = array;
187 m_lastArrayVersion = m_arrayVersion;
188 } 178 }
189 return m_array; 179 return m_array;
190 } 180 }