crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianUtils/Threading/MultiThreadedProcessor.cs
equal
deleted
inserted
replaced
135 Random r = new Random( DateTime.Now.Millisecond ); |
135 Random r = new Random( DateTime.Now.Millisecond ); |
136 // |
136 // |
137 int count = System.Environment.ProcessorCount; |
137 int count = System.Environment.ProcessorCount; |
138 for ( int i = 0; i < count; i++ ) |
138 for ( int i = 0; i < count; i++ ) |
139 { |
139 { |
|
140 System.Console.WriteLine("Creating thread " + i); |
|
141 |
140 string name = string.Format( "Processor Thread {0:d3} {1:d8}", i, r.Next() ); |
142 string name = string.Format( "Processor Thread {0:d3} {1:d8}", i, r.Next() ); |
141 Thread t = new Thread( new ThreadStart( RunThread ) ); |
143 Thread t = new Thread( new ThreadStart( RunThread ) ); |
142 t.IsBackground = true; |
144 t.IsBackground = true; |
143 t.Priority = iThreadPriorities; |
145 t.Priority = iThreadPriorities; |
144 iThreads.Add( t ); |
146 iThreads.Add( t ); |
201 else |
203 else |
202 { |
204 { |
203 // Will be done by "Start" |
205 // Will be done by "Start" |
204 } |
206 } |
205 |
207 |
206 // Always release the blocker to "unblock" the main thread |
208 try |
207 ReleaseBlocker(); |
209 { |
|
210 |
|
211 // Always release the blocker to "unblock" the main thread |
|
212 ReleaseBlocker(); |
|
213 |
|
214 } |
|
215 catch (Exception e) |
|
216 { |
|
217 //eerlehto |
|
218 System.Console.WriteLine("{0} Caught an exception from ReleaseBlocker!", e); |
|
219 //throw; |
|
220 |
|
221 } |
208 } |
222 } |
209 } |
223 } |
210 |
224 |
211 private void OperationComplete() |
225 private void OperationComplete() |
212 { |
226 { |
213 OnEvent( MultiThreadedProcessor<T>.TEvent.EEventCompleted ); |
227 OnEvent( MultiThreadedProcessor<T>.TEvent.EEventCompleted ); |
214 } |
228 } |
215 |
229 |
216 private void DestroyBlocker() |
230 private void DestroyBlocker() |
217 { |
231 { |
218 if ( iSynchronousBlocker != null ) |
232 lock (iBlockerLock) |
219 { |
233 { |
220 iSynchronousBlocker.Close(); |
234 if (iSynchronousBlocker != null) |
221 iSynchronousBlocker = null; |
235 { |
|
236 iSynchronousBlocker.Close(); |
|
237 iSynchronousBlocker = null; |
|
238 |
|
239 } |
222 } |
240 } |
223 } |
241 } |
224 |
242 |
225 private void ReleaseBlocker() |
243 private void ReleaseBlocker() |
226 { |
244 { |
227 if ( iSynchronousBlocker != null ) |
245 lock (iBlockerLock) |
228 { |
246 { |
229 iSynchronousBlocker.Set(); |
247 if (iSynchronousBlocker != null) |
230 } |
248 { |
|
249 iSynchronousBlocker.Set(); |
|
250 } |
|
251 } |
231 } |
252 } |
232 |
253 |
233 protected virtual void OnEvent( TEvent aEvent ) |
254 protected virtual void OnEvent( TEvent aEvent ) |
234 { |
255 { |
235 EventHandler( aEvent ); |
256 EventHandler( aEvent ); |
240 protected override void CleanupManagedResources() |
261 protected override void CleanupManagedResources() |
241 { |
262 { |
242 try |
263 try |
243 { |
264 { |
244 base.CleanupManagedResources(); |
265 base.CleanupManagedResources(); |
|
266 } |
|
267 catch (Exception e) |
|
268 { |
|
269 System.Console.WriteLine("Caught an exception inCleanupManagedResources!"); |
|
270 System.Console.WriteLine(e.StackTrace); |
|
271 throw; |
245 } |
272 } |
246 finally |
273 finally |
247 { |
274 { |
248 DestroyBlocker(); |
275 DestroyBlocker(); |
249 } |
276 } |
254 private readonly int iProcessorCount; |
281 private readonly int iProcessorCount; |
255 private readonly ThreadPriority iThreadPriorities; |
282 private readonly ThreadPriority iThreadPriorities; |
256 private BlockingQueue<T> iQueue = new BlockingQueue<T>(); |
283 private BlockingQueue<T> iQueue = new BlockingQueue<T>(); |
257 private List<Thread> iThreads = new List<Thread>(); |
284 private List<Thread> iThreads = new List<Thread>(); |
258 private ManualResetEvent iSynchronousBlocker = null; |
285 private ManualResetEvent iSynchronousBlocker = null; |
|
286 private Object iBlockerLock = new Object(); |
259 private TSynchronicity iSynchronicity = TSynchronicity.ESynchronous; |
287 private TSynchronicity iSynchronicity = TSynchronicity.ESynchronous; |
260 #endregion |
288 #endregion |
261 } |
289 } |
262 } |
290 } |