comparison Implab/Parallels/DispatchPool.cs @ 92:4c0e5ef99986 v2

rewritten tracing
author cin
date Wed, 22 Oct 2014 18:37:56 +0400
parents ce0171cacec4
children dc4942d09e74
comparison
equal deleted inserted replaced
91:cdaaf4792c22 92:4c0e5ef99986
1 using System; 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading; 2 using System.Threading;
6 using System.Diagnostics;
7 3
8 namespace Implab.Parallels { 4 namespace Implab.Parallels {
9 public abstract class DispatchPool<TUnit> : IDisposable { 5 public abstract class DispatchPool<TUnit> : IDisposable {
10 readonly int m_minThreadsLimit; 6 readonly int m_minThreadsLimit;
11 readonly int m_maxThreadsLimit; 7 readonly int m_maxThreadsLimit;
148 #endregion 144 #endregion
149 145
150 protected bool StartWorker() { 146 protected bool StartWorker() {
151 if (AllocateThreadSlot()) { 147 if (AllocateThreadSlot()) {
152 // slot successfully allocated 148 // slot successfully allocated
153 var worker = new Thread(this.Worker); 149 var worker = new Thread(Worker);
154 worker.IsBackground = true; 150 worker.IsBackground = true;
155 worker.Start(); 151 worker.Start();
156 152
157 return true; 153 return true;
158 } else {
159 return false;
160 } 154 }
155 return false;
161 } 156 }
162 157
163 protected abstract void InvokeUnit(TUnit unit); 158 protected abstract void InvokeUnit(TUnit unit);
164 159
165 protected virtual void Worker() { 160 protected virtual void Worker() {