replace some locked objects by .net4.0 concurrent objects
parent
b5910cfdb7
commit
73aa752034
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using log4net;
|
using log4net;
|
||||||
|
@ -46,10 +47,9 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
|
|
||||||
private readonly BaseHttpServer m_server;
|
private readonly BaseHttpServer m_server;
|
||||||
|
|
||||||
private Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>> m_bycontext;
|
private ConcurrentDictionary <PollServiceHttpRequest,ConcurrentQueue<PollServiceHttpRequest>> m_bycontext;
|
||||||
private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>();
|
private BlockingCollection<PollServiceHttpRequest> m_requests = new BlockingCollection<PollServiceHttpRequest>();
|
||||||
private static Queue<PollServiceHttpRequest> m_retryRequests = new Queue<PollServiceHttpRequest>();
|
private static ConcurrentQueue<PollServiceHttpRequest> m_retryRequests = new ConcurrentQueue<PollServiceHttpRequest>();
|
||||||
|
|
||||||
private uint m_WorkerThreadCount = 0;
|
private uint m_WorkerThreadCount = 0;
|
||||||
private Thread[] m_workerThreads;
|
private Thread[] m_workerThreads;
|
||||||
private Thread m_retrysThread;
|
private Thread m_retrysThread;
|
||||||
|
@ -66,7 +66,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
m_workerThreads = new Thread[m_WorkerThreadCount];
|
m_workerThreads = new Thread[m_WorkerThreadCount];
|
||||||
|
|
||||||
PollServiceHttpRequestComparer preqCp = new PollServiceHttpRequestComparer();
|
PollServiceHttpRequestComparer preqCp = new PollServiceHttpRequestComparer();
|
||||||
m_bycontext = new Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>>(preqCp);
|
m_bycontext = new ConcurrentDictionary <PollServiceHttpRequest, ConcurrentQueue<PollServiceHttpRequest>>(preqCp);
|
||||||
|
|
||||||
STPStartInfo startInfo = new STPStartInfo();
|
STPStartInfo startInfo = new STPStartInfo();
|
||||||
startInfo.IdleTimeout = 30000;
|
startInfo.IdleTimeout = 30000;
|
||||||
|
@ -113,23 +113,23 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
{
|
{
|
||||||
if (m_running)
|
if (m_running)
|
||||||
{
|
{
|
||||||
lock (m_retryRequests)
|
// lock (m_retryRequests)
|
||||||
m_retryRequests.Enqueue(req);
|
m_retryRequests.Enqueue(req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Enqueue(PollServiceHttpRequest req)
|
public void Enqueue(PollServiceHttpRequest req)
|
||||||
{
|
{
|
||||||
lock (m_bycontext)
|
// lock (m_bycontext)
|
||||||
{
|
{
|
||||||
Queue<PollServiceHttpRequest> ctxQeueue;
|
ConcurrentQueue<PollServiceHttpRequest> ctxQeueue;
|
||||||
if (m_bycontext.TryGetValue(req, out ctxQeueue))
|
if (m_bycontext.TryGetValue(req, out ctxQeueue))
|
||||||
{
|
{
|
||||||
ctxQeueue.Enqueue(req);
|
ctxQeueue.Enqueue(req);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ctxQeueue = new Queue<PollServiceHttpRequest>();
|
ctxQeueue = new ConcurrentQueue<PollServiceHttpRequest>();
|
||||||
m_bycontext[req] = ctxQeueue;
|
m_bycontext[req] = ctxQeueue;
|
||||||
EnqueueInt(req);
|
EnqueueInt(req);
|
||||||
}
|
}
|
||||||
|
@ -138,19 +138,20 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
|
|
||||||
public void byContextDequeue(PollServiceHttpRequest req)
|
public void byContextDequeue(PollServiceHttpRequest req)
|
||||||
{
|
{
|
||||||
Queue<PollServiceHttpRequest> ctxQeueue;
|
ConcurrentQueue<PollServiceHttpRequest> ctxQeueue;
|
||||||
lock (m_bycontext)
|
// lock (m_bycontext)
|
||||||
{
|
{
|
||||||
if (m_bycontext.TryGetValue(req, out ctxQeueue))
|
if (m_bycontext.TryGetValue(req, out ctxQeueue))
|
||||||
{
|
{
|
||||||
if (ctxQeueue.Count > 0)
|
if (!ctxQeueue.IsEmpty)
|
||||||
{
|
{
|
||||||
PollServiceHttpRequest newreq = ctxQeueue.Dequeue();
|
PollServiceHttpRequest newreq;
|
||||||
|
if(ctxQeueue.TryDequeue(out newreq))
|
||||||
EnqueueInt(newreq);
|
EnqueueInt(newreq);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_bycontext.Remove(req);
|
m_bycontext.TryRemove(req, out ctxQeueue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,13 +159,13 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
|
|
||||||
public void DropByContext(PollServiceHttpRequest req)
|
public void DropByContext(PollServiceHttpRequest req)
|
||||||
{
|
{
|
||||||
Queue<PollServiceHttpRequest> ctxQeueue;
|
ConcurrentQueue<PollServiceHttpRequest> ctxQeueue;
|
||||||
lock (m_bycontext)
|
lock (m_bycontext)
|
||||||
{
|
{
|
||||||
if (m_bycontext.TryGetValue(req, out ctxQeueue))
|
if (m_bycontext.ContainsKey(req))
|
||||||
{
|
{
|
||||||
ctxQeueue.Clear();
|
// ctxQeueue.Clear();
|
||||||
m_bycontext.Remove(req);
|
m_bycontext.TryRemove(req, out ctxQeueue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,20 +173,21 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
public void EnqueueInt(PollServiceHttpRequest req)
|
public void EnqueueInt(PollServiceHttpRequest req)
|
||||||
{
|
{
|
||||||
if (m_running)
|
if (m_running)
|
||||||
m_requests.Enqueue(req);
|
m_requests.Add(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckRetries()
|
private void CheckRetries()
|
||||||
{
|
{
|
||||||
|
PollServiceHttpRequest req;
|
||||||
while (m_running)
|
while (m_running)
|
||||||
|
|
||||||
{
|
{
|
||||||
Thread.Sleep(100); // let the world move .. back to faster rate
|
Thread.Sleep(100); // let the world move .. back to faster rate
|
||||||
Watchdog.UpdateThread();
|
Watchdog.UpdateThread();
|
||||||
lock (m_retryRequests)
|
// lock (m_retryRequests)
|
||||||
{
|
{
|
||||||
while (m_retryRequests.Count > 0 && m_running)
|
while (m_retryRequests.Count > 0 && m_running)
|
||||||
m_requests.Enqueue(m_retryRequests.Dequeue());
|
if(m_retryRequests.TryDequeue(out req))
|
||||||
|
m_requests.Add(req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,8 +205,8 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
|
|
||||||
// any entry in m_bycontext should have a active request on the other queues
|
// any entry in m_bycontext should have a active request on the other queues
|
||||||
// so just delete contents to easy GC
|
// so just delete contents to easy GC
|
||||||
foreach (Queue<PollServiceHttpRequest> qu in m_bycontext.Values)
|
// foreach (Queue<PollServiceHttpRequest> qu in m_bycontext.Values)
|
||||||
qu.Clear();
|
// qu.Clear();
|
||||||
m_bycontext.Clear();
|
m_bycontext.Clear();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -220,13 +222,13 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
|
|
||||||
PollServiceHttpRequest wreq;
|
PollServiceHttpRequest wreq;
|
||||||
|
|
||||||
m_retryRequests.Clear();
|
// m_retryRequests.Clear();
|
||||||
|
|
||||||
while (m_requests.Count() > 0)
|
while (m_requests.Count > 0)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
wreq = m_requests.Dequeue(0);
|
wreq = m_requests.Take();
|
||||||
wreq.DoHTTPstop(m_server);
|
wreq.DoHTTPstop(m_server);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
@ -234,7 +236,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_requests.Clear();
|
// m_requests.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// work threads
|
// work threads
|
||||||
|
@ -243,7 +245,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
{
|
{
|
||||||
while (m_running)
|
while (m_running)
|
||||||
{
|
{
|
||||||
PollServiceHttpRequest req = m_requests.Dequeue(4500);
|
PollServiceHttpRequest req = m_requests.Take();
|
||||||
Watchdog.UpdateThread();
|
Watchdog.UpdateThread();
|
||||||
if(req == null)
|
if(req == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue