aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorDiva Canto2009-10-07 18:54:08 -0700
committerDiva Canto2009-10-07 18:54:08 -0700
commitc71b3e730d8027b31eb3300c747d011a6e38030e (patch)
treee8920b3046f46c55f7a8e0ea319d36bbca73f2a1 /OpenSim/Region
parentPrintout one more field in show threads, but this won't buy us much. (diff)
downloadopensim-SC-c71b3e730d8027b31eb3300c747d011a6e38030e.zip
opensim-SC-c71b3e730d8027b31eb3300c747d011a6e38030e.tar.gz
opensim-SC-c71b3e730d8027b31eb3300c747d011a6e38030e.tar.bz2
opensim-SC-c71b3e730d8027b31eb3300c747d011a6e38030e.tar.xz
Changed the locking mechanism, because the existing one is causing deadlocks to occur.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs125
1 files changed, 100 insertions, 25 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs
index 7d2da68..9be9480 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs
@@ -41,6 +41,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
41 Dictionary<IPEndPoint, LLUDPClient> Dictionary2; 41 Dictionary<IPEndPoint, LLUDPClient> Dictionary2;
42 LLUDPClient[] Array; 42 LLUDPClient[] Array;
43 ReaderWriterLockImpl rwLock = new ReaderWriterLockImpl(); 43 ReaderWriterLockImpl rwLock = new ReaderWriterLockImpl();
44 object m_sync = new object();
44 45
45 public UDPClientCollection() 46 public UDPClientCollection()
46 { 47 {
@@ -58,9 +59,37 @@ namespace OpenSim.Region.ClientStack.LindenUDP
58 59
59 public void Add(UUID key1, IPEndPoint key2, LLUDPClient value) 60 public void Add(UUID key1, IPEndPoint key2, LLUDPClient value)
60 { 61 {
61 rwLock.EnterWriteLock(); 62 //rwLock.EnterWriteLock();
62 63
63 try 64 //try
65 //{
66 // if (Dictionary1.ContainsKey(key1))
67 // {
68 // if (!Dictionary2.ContainsKey(key2))
69 // throw new ArgumentException("key1 exists in the dictionary but not key2");
70 // }
71 // else if (Dictionary2.ContainsKey(key2))
72 // {
73 // if (!Dictionary1.ContainsKey(key1))
74 // throw new ArgumentException("key2 exists in the dictionary but not key1");
75 // }
76
77 // Dictionary1[key1] = value;
78 // Dictionary2[key2] = value;
79
80 // LLUDPClient[] oldArray = Array;
81 // int oldLength = oldArray.Length;
82
83 // LLUDPClient[] newArray = new LLUDPClient[oldLength + 1];
84 // for (int i = 0; i < oldLength; i++)
85 // newArray[i] = oldArray[i];
86 // newArray[oldLength] = value;
87
88 // Array = newArray;
89 //}
90 //finally { rwLock.ExitWriteLock(); }
91
92 lock (m_sync)
64 { 93 {
65 if (Dictionary1.ContainsKey(key1)) 94 if (Dictionary1.ContainsKey(key1))
66 { 95 {
@@ -86,14 +115,41 @@ namespace OpenSim.Region.ClientStack.LindenUDP
86 115
87 Array = newArray; 116 Array = newArray;
88 } 117 }
89 finally { rwLock.ExitWriteLock(); } 118
90 } 119 }
91 120
92 public bool Remove(UUID key1, IPEndPoint key2) 121 public bool Remove(UUID key1, IPEndPoint key2)
93 { 122 {
94 rwLock.EnterWriteLock(); 123 //rwLock.EnterWriteLock();
124
125 //try
126 //{
127 // LLUDPClient value;
128 // if (Dictionary1.TryGetValue(key1, out value))
129 // {
130 // Dictionary1.Remove(key1);
131 // Dictionary2.Remove(key2);
132
133 // LLUDPClient[] oldArray = Array;
134 // int oldLength = oldArray.Length;
135
136 // LLUDPClient[] newArray = new LLUDPClient[oldLength - 1];
137 // int j = 0;
138 // for (int i = 0; i < oldLength; i++)
139 // {
140 // if (oldArray[i] != value)
141 // newArray[j++] = oldArray[i];
142 // }
143
144 // Array = newArray;
145 // return true;
146 // }
147 //}
148 //finally { rwLock.ExitWriteLock(); }
95 149
96 try 150 //return false;
151
152 lock (m_sync)
97 { 153 {
98 LLUDPClient value; 154 LLUDPClient value;
99 if (Dictionary1.TryGetValue(key1, out value)) 155 if (Dictionary1.TryGetValue(key1, out value))
@@ -116,22 +172,30 @@ namespace OpenSim.Region.ClientStack.LindenUDP
116 return true; 172 return true;
117 } 173 }
118 } 174 }
119 finally { rwLock.ExitWriteLock(); }
120 175
121 return false; 176 return false;
177
122 } 178 }
123 179
124 public void Clear() 180 public void Clear()
125 { 181 {
126 rwLock.EnterWriteLock(); 182 //rwLock.EnterWriteLock();
183
184 //try
185 //{
186 // Dictionary1.Clear();
187 // Dictionary2.Clear();
188 // Array = new LLUDPClient[0];
189 //}
190 //finally { rwLock.ExitWriteLock(); }
127 191
128 try 192 lock (m_sync)
129 { 193 {
130 Dictionary1.Clear(); 194 Dictionary1.Clear();
131 Dictionary2.Clear(); 195 Dictionary2.Clear();
132 Array = new LLUDPClient[0]; 196 Array = new LLUDPClient[0];
133 } 197 }
134 finally { rwLock.ExitWriteLock(); } 198
135 } 199 }
136 200
137 public int Count 201 public int Count
@@ -151,35 +215,46 @@ namespace OpenSim.Region.ClientStack.LindenUDP
151 215
152 public bool TryGetValue(UUID key, out LLUDPClient value) 216 public bool TryGetValue(UUID key, out LLUDPClient value)
153 { 217 {
154 bool success; 218 //bool success;
155 bool doLock = !rwLock.IsUpgradeableReadLockHeld; 219 //bool doLock = !rwLock.IsUpgradeableReadLockHeld;
156 if (doLock) rwLock.EnterReadLock(); 220 //if (doLock) rwLock.EnterReadLock();
221
222 //try { success = Dictionary1.TryGetValue(key, out value); }
223 //finally { if (doLock) rwLock.ExitReadLock(); }
157 224
158 try { success = Dictionary1.TryGetValue(key, out value); } 225 //return success;
159 finally { if (doLock) rwLock.ExitReadLock(); } 226
227 lock (m_sync)
228 return Dictionary1.TryGetValue(key, out value);
160 229
161 return success;
162 } 230 }
163 231
164 public bool TryGetValue(IPEndPoint key, out LLUDPClient value) 232 public bool TryGetValue(IPEndPoint key, out LLUDPClient value)
165 { 233 {
166 bool success; 234 //bool success;
167 bool doLock = !rwLock.IsUpgradeableReadLockHeld; 235 //bool doLock = !rwLock.IsUpgradeableReadLockHeld;
168 if (doLock) rwLock.EnterReadLock(); 236 //if (doLock) rwLock.EnterReadLock();
237
238 //try { success = Dictionary2.TryGetValue(key, out value); }
239 //finally { if (doLock) rwLock.ExitReadLock(); }
169 240
170 try { success = Dictionary2.TryGetValue(key, out value); } 241 //return success;
171 finally { if (doLock) rwLock.ExitReadLock(); }
172 242
173 return success; 243 lock (m_sync)
244 return Dictionary2.TryGetValue(key, out value);
174 } 245 }
175 246
176 public void ForEach(Action<LLUDPClient> action) 247 public void ForEach(Action<LLUDPClient> action)
177 { 248 {
178 bool doLock = !rwLock.IsUpgradeableReadLockHeld; 249 //bool doLock = !rwLock.IsUpgradeableReadLockHeld;
179 if (doLock) rwLock.EnterUpgradeableReadLock(); 250 //if (doLock) rwLock.EnterUpgradeableReadLock();
251
252 //try { Parallel.ForEach<LLUDPClient>(Array, action); }
253 //finally { if (doLock) rwLock.ExitUpgradeableReadLock(); }
254
255 lock (m_sync)
256 Parallel.ForEach<LLUDPClient>(Array, action);
180 257
181 try { Parallel.ForEach<LLUDPClient>(Array, action); }
182 finally { if (doLock) rwLock.ExitUpgradeableReadLock(); }
183 } 258 }
184 } 259 }
185} 260}