From 7df325c275c90d5be750082a9b8dafd92ef14669 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 18 Mar 2014 23:05:49 +0000 Subject: [PATCH] Extend locking in BlockingQueue to cover operations that are not guaranteed to be thread-safe --- OpenSim/Framework/BlockingQueue.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/OpenSim/Framework/BlockingQueue.cs b/OpenSim/Framework/BlockingQueue.cs index 3e90fac569..d11ad11c17 100644 --- a/OpenSim/Framework/BlockingQueue.cs +++ b/OpenSim/Framework/BlockingQueue.cs @@ -98,11 +98,11 @@ namespace OpenSim.Framework /// public bool Contains(T item) { - if (m_queue.Count < 1 && m_pqueue.Count < 1) - return false; - lock (m_queueSync) { + if (m_queue.Count < 1 && m_pqueue.Count < 1) + return false; + if (m_pqueue.Contains(item)) return true; return m_queue.Contains(item); @@ -112,12 +112,10 @@ namespace OpenSim.Framework /// /// Return a count of the number of requests on this queue. /// - /// - /// This method is not thread-safe. Do not rely on the result without consistent external locking. - /// public int Count() { - return m_queue.Count + m_pqueue.Count; + lock (m_queueSync) + return m_queue.Count + m_pqueue.Count; } /// @@ -128,11 +126,11 @@ namespace OpenSim.Framework /// public T[] GetQueueArray() { - if (m_queue.Count < 1 && m_pqueue.Count < 1) - return new T[0]; - lock (m_queueSync) { + if (m_queue.Count < 1 && m_pqueue.Count < 1) + return new T[0]; + return m_queue.ToArray(); } }