diff options
author | Justin Clark-Casey (justincc) | 2014-03-19 01:40:56 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2014-03-19 01:40:56 +0000 |
commit | cf97535d9e6c1b54994edd5cb646fe891187d33b (patch) | |
tree | 7519a37b24c10824b893fac3319eeaabe75be8d4 /OpenSim | |
parent | Simplify DoubleQueue to eliminate redundant sempahore work. (diff) | |
download | opensim-SC_OLD-cf97535d9e6c1b54994edd5cb646fe891187d33b.zip opensim-SC_OLD-cf97535d9e6c1b54994edd5cb646fe891187d33b.tar.gz opensim-SC_OLD-cf97535d9e6c1b54994edd5cb646fe891187d33b.tar.bz2 opensim-SC_OLD-cf97535d9e6c1b54994edd5cb646fe891187d33b.tar.xz |
Revert "Simplify DoubleQueue to eliminate redundant sempahore work."
This reverts commit 52b7b40034ddbb21d06b11ddc4eb6d766b0f616d.
Got the semantics wrong - the sempahore is required so that the blocking thread waits for a signal.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Framework/Util.cs | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index f6e76dc..efaed62 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -2296,6 +2296,11 @@ 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 | } | ||
2299 | 2304 | ||
2300 | public virtual int Count | 2305 | public virtual int Count |
2301 | { | 2306 | { |
@@ -2324,7 +2329,11 @@ namespace OpenSim.Framework | |||
2324 | private void Enqueue(Queue<T> q, T data) | 2329 | private void Enqueue(Queue<T> q, T data) |
2325 | { | 2330 | { |
2326 | lock (m_syncRoot) | 2331 | lock (m_syncRoot) |
2332 | { | ||
2327 | q.Enqueue(data); | 2333 | q.Enqueue(data); |
2334 | m_s.WaitOne(0); | ||
2335 | m_s.Release(); | ||
2336 | } | ||
2328 | } | 2337 | } |
2329 | 2338 | ||
2330 | public virtual T Dequeue() | 2339 | public virtual T Dequeue() |
@@ -2354,31 +2363,42 @@ namespace OpenSim.Framework | |||
2354 | 2363 | ||
2355 | public bool Dequeue(TimeSpan wait, ref T res) | 2364 | public bool Dequeue(TimeSpan wait, ref T res) |
2356 | { | 2365 | { |
2357 | if (!Monitor.TryEnter(m_syncRoot, wait)) | 2366 | if (!m_s.WaitOne(wait)) |
2358 | return false; | 2367 | return false; |
2359 | 2368 | ||
2360 | try | 2369 | lock (m_syncRoot) |
2361 | { | 2370 | { |
2362 | if (m_highQueue.Count > 0) | 2371 | if (m_highQueue.Count > 0) |
2363 | res = m_highQueue.Dequeue(); | 2372 | res = m_highQueue.Dequeue(); |
2364 | else if (m_lowQueue.Count > 0) | 2373 | else if (m_lowQueue.Count > 0) |
2365 | res = m_lowQueue.Dequeue(); | 2374 | res = m_lowQueue.Dequeue(); |
2366 | 2375 | ||
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 | |||
2367 | return true; | 2387 | return true; |
2368 | } | 2388 | } |
2369 | finally | ||
2370 | { | ||
2371 | Monitor.Exit(m_syncRoot); | ||
2372 | } | ||
2373 | } | 2389 | } |
2374 | 2390 | ||
2375 | public virtual void Clear() | 2391 | public virtual void Clear() |
2376 | { | 2392 | { |
2393 | |||
2377 | lock (m_syncRoot) | 2394 | lock (m_syncRoot) |
2378 | { | 2395 | { |
2396 | // Make sure sem count is 0 | ||
2397 | m_s.WaitOne(0); | ||
2398 | |||
2379 | m_lowQueue.Clear(); | 2399 | m_lowQueue.Clear(); |
2380 | m_highQueue.Clear(); | 2400 | m_highQueue.Clear(); |
2381 | } | 2401 | } |
2382 | } | 2402 | } |
2383 | } | 2403 | } |
2384 | } \ No newline at end of file | 2404 | } |