Extend locking in BlockingQueue to cover operations that are not guaranteed to be thread-safe
parent
fdcd392582
commit
7df325c275
|
@ -97,12 +97,12 @@ namespace OpenSim.Framework
|
||||||
/// This method is not thread-safe. Do not rely on the result without consistent external locking.
|
/// This method is not thread-safe. Do not rely on the result without consistent external locking.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public bool Contains(T item)
|
public bool Contains(T item)
|
||||||
|
{
|
||||||
|
lock (m_queueSync)
|
||||||
{
|
{
|
||||||
if (m_queue.Count < 1 && m_pqueue.Count < 1)
|
if (m_queue.Count < 1 && m_pqueue.Count < 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
lock (m_queueSync)
|
|
||||||
{
|
|
||||||
if (m_pqueue.Contains(item))
|
if (m_pqueue.Contains(item))
|
||||||
return true;
|
return true;
|
||||||
return m_queue.Contains(item);
|
return m_queue.Contains(item);
|
||||||
|
@ -112,11 +112,9 @@ namespace OpenSim.Framework
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return a count of the number of requests on this queue.
|
/// Return a count of the number of requests on this queue.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
|
||||||
/// This method is not thread-safe. Do not rely on the result without consistent external locking.
|
|
||||||
/// </remarks>
|
|
||||||
public int Count()
|
public int Count()
|
||||||
{
|
{
|
||||||
|
lock (m_queueSync)
|
||||||
return m_queue.Count + m_pqueue.Count;
|
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.
|
/// This method is not thread-safe. Do not rely on the result without consistent external locking.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public T[] GetQueueArray()
|
public T[] GetQueueArray()
|
||||||
|
{
|
||||||
|
lock (m_queueSync)
|
||||||
{
|
{
|
||||||
if (m_queue.Count < 1 && m_pqueue.Count < 1)
|
if (m_queue.Count < 1 && m_pqueue.Count < 1)
|
||||||
return new T[0];
|
return new T[0];
|
||||||
|
|
||||||
lock (m_queueSync)
|
|
||||||
{
|
|
||||||
return m_queue.ToArray();
|
return m_queue.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue