Extend locking in BlockingQueue to cover operations that are not guaranteed to be thread-safe

0.8.0.3
Justin Clark-Casey (justincc) 2014-03-18 23:05:49 +00:00
parent fdcd392582
commit 7df325c275
1 changed files with 8 additions and 10 deletions

View File

@ -97,12 +97,12 @@ namespace OpenSim.Framework
/// This method is not thread-safe. Do not rely on the result without consistent external locking.
/// </remarks>
public bool Contains(T item)
{
lock (m_queueSync)
{
if (m_queue.Count < 1 && m_pqueue.Count < 1)
return false;
lock (m_queueSync)
{
if (m_pqueue.Contains(item))
return true;
return m_queue.Contains(item);
@ -112,11 +112,9 @@ namespace OpenSim.Framework
/// <summary>
/// Return a count of the number of requests on this queue.
/// </summary>
/// <remarks>
/// This method is not thread-safe. Do not rely on the result without consistent external locking.
/// </remarks>
public int Count()
{
lock (m_queueSync)
return m_queue.Count + m_pqueue.Count;
}
@ -127,12 +125,12 @@ namespace OpenSim.Framework
/// This method is not thread-safe. Do not rely on the result without consistent external locking.
/// </remarks>
public T[] GetQueueArray()
{
lock (m_queueSync)
{
if (m_queue.Count < 1 && m_pqueue.Count < 1)
return new T[0];
lock (m_queueSync)
{
return m_queue.ToArray();
}
}