Revert "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 21a09ad3ad.

After more analysis and discussion, it is apparant that the Count(), Contains() and GetQueueArray() cannot be made thread-safe anyway without external locking
And this change appears to have a positive impact on performance.
I still believe that Monitor.Exit() will not release any thread for Monitor.Wait(), as per http://msdn.microsoft.com/en-gb/library/vstudio/system.threading.monitor.exit%28v=vs.100%29.aspx
so this should in theory make no difference, though mono implementation issues could possibly be coming into play.
cpu-performance
Justin Clark-Casey (justincc) 2013-07-16 23:00:07 +01:00
parent 21a09ad3ad
commit 50b8ab60f2
1 changed files with 8 additions and 5 deletions

View File

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