aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorUbitUmarov2017-06-10 04:18:31 +0100
committerUbitUmarov2017-06-10 04:18:31 +0100
commit73aa7520341fec13416661f19ea19cf138b6386d (patch)
tree1e42c866b07d9cae7d17cdd120474929d3b4ddbe
parentmerge (diff)
downloadopensim-SC-73aa7520341fec13416661f19ea19cf138b6386d.zip
opensim-SC-73aa7520341fec13416661f19ea19cf138b6386d.tar.gz
opensim-SC-73aa7520341fec13416661f19ea19cf138b6386d.tar.bz2
opensim-SC-73aa7520341fec13416661f19ea19cf138b6386d.tar.xz
replace some locked objects by .net4.0 concurrent objects
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs62
1 files changed, 32 insertions, 30 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
index cbdd781..9115b62 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Concurrent;
30using System.Threading; 31using System.Threading;
31using System.Reflection; 32using System.Reflection;
32using log4net; 33using log4net;
@@ -46,10 +47,9 @@ namespace OpenSim.Framework.Servers.HttpServer
46 47
47 private readonly BaseHttpServer m_server; 48 private readonly BaseHttpServer m_server;
48 49
49 private Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>> m_bycontext; 50 private ConcurrentDictionary <PollServiceHttpRequest,ConcurrentQueue<PollServiceHttpRequest>> m_bycontext;
50 private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>(); 51 private BlockingCollection<PollServiceHttpRequest> m_requests = new BlockingCollection<PollServiceHttpRequest>();
51 private static Queue<PollServiceHttpRequest> m_retryRequests = new Queue<PollServiceHttpRequest>(); 52 private static ConcurrentQueue<PollServiceHttpRequest> m_retryRequests = new ConcurrentQueue<PollServiceHttpRequest>();
52
53 private uint m_WorkerThreadCount = 0; 53 private uint m_WorkerThreadCount = 0;
54 private Thread[] m_workerThreads; 54 private Thread[] m_workerThreads;
55 private Thread m_retrysThread; 55 private Thread m_retrysThread;
@@ -66,7 +66,7 @@ namespace OpenSim.Framework.Servers.HttpServer
66 m_workerThreads = new Thread[m_WorkerThreadCount]; 66 m_workerThreads = new Thread[m_WorkerThreadCount];
67 67
68 PollServiceHttpRequestComparer preqCp = new PollServiceHttpRequestComparer(); 68 PollServiceHttpRequestComparer preqCp = new PollServiceHttpRequestComparer();
69 m_bycontext = new Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>>(preqCp); 69 m_bycontext = new ConcurrentDictionary <PollServiceHttpRequest, ConcurrentQueue<PollServiceHttpRequest>>(preqCp);
70 70
71 STPStartInfo startInfo = new STPStartInfo(); 71 STPStartInfo startInfo = new STPStartInfo();
72 startInfo.IdleTimeout = 30000; 72 startInfo.IdleTimeout = 30000;
@@ -113,23 +113,23 @@ namespace OpenSim.Framework.Servers.HttpServer
113 { 113 {
114 if (m_running) 114 if (m_running)
115 { 115 {
116 lock (m_retryRequests) 116// lock (m_retryRequests)
117 m_retryRequests.Enqueue(req); 117 m_retryRequests.Enqueue(req);
118 } 118 }
119 } 119 }
120 120
121 public void Enqueue(PollServiceHttpRequest req) 121 public void Enqueue(PollServiceHttpRequest req)
122 { 122 {
123 lock (m_bycontext) 123// lock (m_bycontext)
124 { 124 {
125 Queue<PollServiceHttpRequest> ctxQeueue; 125 ConcurrentQueue<PollServiceHttpRequest> ctxQeueue;
126 if (m_bycontext.TryGetValue(req, out ctxQeueue)) 126 if (m_bycontext.TryGetValue(req, out ctxQeueue))
127 { 127 {
128 ctxQeueue.Enqueue(req); 128 ctxQeueue.Enqueue(req);
129 } 129 }
130 else 130 else
131 { 131 {
132 ctxQeueue = new Queue<PollServiceHttpRequest>(); 132 ctxQeueue = new ConcurrentQueue<PollServiceHttpRequest>();
133 m_bycontext[req] = ctxQeueue; 133 m_bycontext[req] = ctxQeueue;
134 EnqueueInt(req); 134 EnqueueInt(req);
135 } 135 }
@@ -138,19 +138,20 @@ namespace OpenSim.Framework.Servers.HttpServer
138 138
139 public void byContextDequeue(PollServiceHttpRequest req) 139 public void byContextDequeue(PollServiceHttpRequest req)
140 { 140 {
141 Queue<PollServiceHttpRequest> ctxQeueue; 141 ConcurrentQueue<PollServiceHttpRequest> ctxQeueue;
142 lock (m_bycontext) 142// lock (m_bycontext)
143 { 143 {
144 if (m_bycontext.TryGetValue(req, out ctxQeueue)) 144 if (m_bycontext.TryGetValue(req, out ctxQeueue))
145 { 145 {
146 if (ctxQeueue.Count > 0) 146 if (!ctxQeueue.IsEmpty)
147 { 147 {
148 PollServiceHttpRequest newreq = ctxQeueue.Dequeue(); 148 PollServiceHttpRequest newreq;
149 EnqueueInt(newreq); 149 if(ctxQeueue.TryDequeue(out newreq))
150 EnqueueInt(newreq);
150 } 151 }
151 else 152 else
152 { 153 {
153 m_bycontext.Remove(req); 154 m_bycontext.TryRemove(req, out ctxQeueue);
154 } 155 }
155 } 156 }
156 } 157 }
@@ -158,13 +159,13 @@ namespace OpenSim.Framework.Servers.HttpServer
158 159
159 public void DropByContext(PollServiceHttpRequest req) 160 public void DropByContext(PollServiceHttpRequest req)
160 { 161 {
161 Queue<PollServiceHttpRequest> ctxQeueue; 162 ConcurrentQueue<PollServiceHttpRequest> ctxQeueue;
162 lock (m_bycontext) 163 lock (m_bycontext)
163 { 164 {
164 if (m_bycontext.TryGetValue(req, out ctxQeueue)) 165 if (m_bycontext.ContainsKey(req))
165 { 166 {
166 ctxQeueue.Clear(); 167// ctxQeueue.Clear();
167 m_bycontext.Remove(req); 168 m_bycontext.TryRemove(req, out ctxQeueue);
168 } 169 }
169 } 170 }
170 } 171 }
@@ -172,20 +173,21 @@ namespace OpenSim.Framework.Servers.HttpServer
172 public void EnqueueInt(PollServiceHttpRequest req) 173 public void EnqueueInt(PollServiceHttpRequest req)
173 { 174 {
174 if (m_running) 175 if (m_running)
175 m_requests.Enqueue(req); 176 m_requests.Add(req);
176 } 177 }
177 178
178 private void CheckRetries() 179 private void CheckRetries()
179 { 180 {
181 PollServiceHttpRequest req;
180 while (m_running) 182 while (m_running)
181
182 { 183 {
183 Thread.Sleep(100); // let the world move .. back to faster rate 184 Thread.Sleep(100); // let the world move .. back to faster rate
184 Watchdog.UpdateThread(); 185 Watchdog.UpdateThread();
185 lock (m_retryRequests) 186// lock (m_retryRequests)
186 { 187 {
187 while (m_retryRequests.Count > 0 && m_running) 188 while (m_retryRequests.Count > 0 && m_running)
188 m_requests.Enqueue(m_retryRequests.Dequeue()); 189 if(m_retryRequests.TryDequeue(out req))
190 m_requests.Add(req);
189 } 191 }
190 } 192 }
191 } 193 }
@@ -203,8 +205,8 @@ namespace OpenSim.Framework.Servers.HttpServer
203 205
204 // any entry in m_bycontext should have a active request on the other queues 206 // any entry in m_bycontext should have a active request on the other queues
205 // so just delete contents to easy GC 207 // so just delete contents to easy GC
206 foreach (Queue<PollServiceHttpRequest> qu in m_bycontext.Values) 208// foreach (Queue<PollServiceHttpRequest> qu in m_bycontext.Values)
207 qu.Clear(); 209// qu.Clear();
208 m_bycontext.Clear(); 210 m_bycontext.Clear();
209 211
210 try 212 try
@@ -220,13 +222,13 @@ namespace OpenSim.Framework.Servers.HttpServer
220 222
221 PollServiceHttpRequest wreq; 223 PollServiceHttpRequest wreq;
222 224
223 m_retryRequests.Clear(); 225// m_retryRequests.Clear();
224 226
225 while (m_requests.Count() > 0) 227 while (m_requests.Count > 0)
226 { 228 {
227 try 229 try
228 { 230 {
229 wreq = m_requests.Dequeue(0); 231 wreq = m_requests.Take();
230 wreq.DoHTTPstop(m_server); 232 wreq.DoHTTPstop(m_server);
231 } 233 }
232 catch 234 catch
@@ -234,7 +236,7 @@ namespace OpenSim.Framework.Servers.HttpServer
234 } 236 }
235 } 237 }
236 238
237 m_requests.Clear(); 239// m_requests.Clear();
238 } 240 }
239 241
240 // work threads 242 // work threads
@@ -243,7 +245,7 @@ namespace OpenSim.Framework.Servers.HttpServer
243 { 245 {
244 while (m_running) 246 while (m_running)
245 { 247 {
246 PollServiceHttpRequest req = m_requests.Dequeue(4500); 248 PollServiceHttpRequest req = m_requests.Take();
247 Watchdog.UpdateThread(); 249 Watchdog.UpdateThread();
248 if(req == null) 250 if(req == null)
249 continue; 251 continue;