aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-03-19 00:48:13 +0000
committerJustin Clark-Casey (justincc)2014-03-19 00:48:13 +0000
commit52b7b40034ddbb21d06b11ddc4eb6d766b0f616d (patch)
treeeac13e0d41876d967afac45bc7293c8afb1638b5 /OpenSim/Framework
parentminor: Put ProcessedFetchInventoryRequests and QueuedFetchInventoryRequests i... (diff)
downloadopensim-SC_OLD-52b7b40034ddbb21d06b11ddc4eb6d766b0f616d.zip
opensim-SC_OLD-52b7b40034ddbb21d06b11ddc4eb6d766b0f616d.tar.gz
opensim-SC_OLD-52b7b40034ddbb21d06b11ddc4eb6d766b0f616d.tar.bz2
opensim-SC_OLD-52b7b40034ddbb21d06b11ddc4eb6d766b0f616d.tar.xz
Simplify DoubleQueue to eliminate redundant sempahore work.
Exclusion is already guaranteed by the lock on m_syncRoot. Semaphore could not allow more than one thread in these sections anyway since the underlying SDK structures are not thread-safe.
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Util.cs34
1 files changed, 7 insertions, 27 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index efaed62..f6e76dc 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -2296,11 +2296,6 @@ namespace OpenSim.Framework
2296 private Queue<T> m_highQueue = new Queue<T>(); 2296 private Queue<T> m_highQueue = new Queue<T>();
2297 2297
2298 private object m_syncRoot = new object(); 2298 private object m_syncRoot = new object();
2299 private Semaphore m_s = new Semaphore(0, 1);
2300
2301 public DoubleQueue()
2302 {
2303 }
2304 2299
2305 public virtual int Count 2300 public virtual int Count
2306 { 2301 {
@@ -2329,11 +2324,7 @@ namespace OpenSim.Framework
2329 private void Enqueue(Queue<T> q, T data) 2324 private void Enqueue(Queue<T> q, T data)
2330 { 2325 {
2331 lock (m_syncRoot) 2326 lock (m_syncRoot)
2332 {
2333 q.Enqueue(data); 2327 q.Enqueue(data);
2334 m_s.WaitOne(0);
2335 m_s.Release();
2336 }
2337 } 2328 }
2338 2329
2339 public virtual T Dequeue() 2330 public virtual T Dequeue()
@@ -2363,42 +2354,31 @@ namespace OpenSim.Framework
2363 2354
2364 public bool Dequeue(TimeSpan wait, ref T res) 2355 public bool Dequeue(TimeSpan wait, ref T res)
2365 { 2356 {
2366 if (!m_s.WaitOne(wait)) 2357 if (!Monitor.TryEnter(m_syncRoot, wait))
2367 return false; 2358 return false;
2368 2359
2369 lock (m_syncRoot) 2360 try
2370 { 2361 {
2371 if (m_highQueue.Count > 0) 2362 if (m_highQueue.Count > 0)
2372 res = m_highQueue.Dequeue(); 2363 res = m_highQueue.Dequeue();
2373 else if (m_lowQueue.Count > 0) 2364 else if (m_lowQueue.Count > 0)
2374 res = m_lowQueue.Dequeue(); 2365 res = m_lowQueue.Dequeue();
2375 2366
2376 if (m_highQueue.Count == 0 && m_lowQueue.Count == 0)
2377 return true;
2378
2379 try
2380 {
2381 m_s.Release();
2382 }
2383 catch
2384 {
2385 }
2386
2387 return true; 2367 return true;
2388 } 2368 }
2369 finally
2370 {
2371 Monitor.Exit(m_syncRoot);
2372 }
2389 } 2373 }
2390 2374
2391 public virtual void Clear() 2375 public virtual void Clear()
2392 { 2376 {
2393
2394 lock (m_syncRoot) 2377 lock (m_syncRoot)
2395 { 2378 {
2396 // Make sure sem count is 0
2397 m_s.WaitOne(0);
2398
2399 m_lowQueue.Clear(); 2379 m_lowQueue.Clear();
2400 m_highQueue.Clear(); 2380 m_highQueue.Clear();
2401 } 2381 }
2402 } 2382 }
2403 } 2383 }
2404} 2384} \ No newline at end of file