Revert "MSDN documentation is unclear about whether exiting a lock() block will trigger a Monitor.Wait() to exit, so avoid some locks that don't actually affect the state of the internal queues in the BlockingQueue class."

This reverts commit 42e2a0d66e

Reverting because unfortunately this introduces race conditions because Contains(), Count() and GetQueueArray() may now end up returning the wrong result if another thread performs a simultaneous update on m_queue.
Code such as PollServiceRequestManager.Stop() relies on the count being correct otherwise a request may be lost.
Also, though some of the internal queue methods do not affect state, they are not thread-safe and could return the wrong result generating the same problem
lock() generates Monitor.Enter() and Monitor.Exit() under the covers.  Monitor.Exit() does not cause Monitor.Wait() to exist, only Pulse() and PulseAll() will do this
Reverted with agreement.
cpu-performance
Justin Clark-Casey (justincc) 2013-07-16 21:54:00 +01:00
parent e0f0b88dec
commit 21a09ad3ad
1 changed files with 5 additions and 8 deletions

View File

@ -58,7 +58,7 @@ namespace OpenSim.Framework
{
lock (m_queueSync)
{
while (m_queue.Count < 1 && m_pqueue.Count < 1)
if (m_queue.Count < 1 && m_pqueue.Count < 1)
{
Monitor.Wait(m_queueSync);
}
@ -91,9 +91,6 @@ namespace OpenSim.Framework
public bool Contains(T item)
{
if (m_queue.Count < 1 && m_pqueue.Count < 1)
return false;
lock (m_queueSync)
{
if (m_pqueue.Contains(item))
@ -104,14 +101,14 @@ namespace OpenSim.Framework
public int Count()
{
return m_queue.Count+m_pqueue.Count;
lock (m_queueSync)
{
return m_queue.Count+m_pqueue.Count;
}
}
public T[] GetQueueArray()
{
if (m_queue.Count < 1 && m_pqueue.Count < 1)
return new T[0];
lock (m_queueSync)
{
return m_queue.ToArray();