Simplify DoubleQueue to eliminate redundant sempahore work.
Exclusion is already guaranteed by the lock on m_syncRoot. Semaphore could not allow more than one thread in these sections anyway since the underlying SDK structures are not thread-safe.0.8.0.3
parent
1497b75361
commit
52b7b40034
|
@ -2296,11 +2296,6 @@ namespace OpenSim.Framework
|
|||
private Queue<T> m_highQueue = new Queue<T>();
|
||||
|
||||
private object m_syncRoot = new object();
|
||||
private Semaphore m_s = new Semaphore(0, 1);
|
||||
|
||||
public DoubleQueue()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual int Count
|
||||
{
|
||||
|
@ -2329,11 +2324,7 @@ namespace OpenSim.Framework
|
|||
private void Enqueue(Queue<T> q, T data)
|
||||
{
|
||||
lock (m_syncRoot)
|
||||
{
|
||||
q.Enqueue(data);
|
||||
m_s.WaitOne(0);
|
||||
m_s.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual T Dequeue()
|
||||
|
@ -2363,39 +2354,28 @@ namespace OpenSim.Framework
|
|||
|
||||
public bool Dequeue(TimeSpan wait, ref T res)
|
||||
{
|
||||
if (!m_s.WaitOne(wait))
|
||||
if (!Monitor.TryEnter(m_syncRoot, wait))
|
||||
return false;
|
||||
|
||||
lock (m_syncRoot)
|
||||
try
|
||||
{
|
||||
if (m_highQueue.Count > 0)
|
||||
res = m_highQueue.Dequeue();
|
||||
else if (m_lowQueue.Count > 0)
|
||||
res = m_lowQueue.Dequeue();
|
||||
|
||||
if (m_highQueue.Count == 0 && m_lowQueue.Count == 0)
|
||||
return true;
|
||||
|
||||
try
|
||||
{
|
||||
m_s.Release();
|
||||
}
|
||||
catch
|
||||
finally
|
||||
{
|
||||
}
|
||||
|
||||
return true;
|
||||
Monitor.Exit(m_syncRoot);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Clear()
|
||||
{
|
||||
|
||||
lock (m_syncRoot)
|
||||
{
|
||||
// Make sure sem count is 0
|
||||
m_s.WaitOne(0);
|
||||
|
||||
m_lowQueue.Clear();
|
||||
m_highQueue.Clear();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue