diff Implab/Parallels/WorkerPool.cs @ 17:7cd4a843b4e4 promises

Improved worker pool
author cin
date Fri, 08 Nov 2013 01:25:42 +0400
parents 5a4b735ba669
children 1c3b3d518480
line wrap: on
line diff
--- a/Implab/Parallels/WorkerPool.cs	Thu Nov 07 20:20:26 2013 +0400
+++ b/Implab/Parallels/WorkerPool.cs	Fri Nov 08 01:25:42 2013 +0400
@@ -57,17 +57,16 @@
             var len = Interlocked.Increment(ref m_queueLength);
             m_queue.Enqueue(unit);
 
-            if (ThreadCount == 0)
-                // force to start
-                WakeNewWorker(false);
+            if(!ExtendPool())
+                WakePool();
         }
 
-        protected override void WakeNewWorker(bool extend) {
-            if (extend && m_queueLength <= m_threshold)
+        protected override bool ExtendPool() {
+            if (m_queueLength <= m_threshold*ThreadCount)
                 // in this case we are in active thread and it request for additional workers
                 // satisfy it only when queue is longer than threshold
-                return;
-            base.WakeNewWorker(extend);
+                return false;
+            return base.ExtendPool();
         }
 
         protected override bool TryDequeue(out Action unit) {