comparison Implab/Parallels/WorkerPool.cs @ 20:1c3b3d518480 promises

refactoring, sync
author cin
date Tue, 12 Nov 2013 02:27:22 +0400
parents 7cd4a843b4e4
children 6a56df4ec59e
comparison
equal deleted inserted replaced
19:e3935fdf59a2 20:1c3b3d518480
55 protected void EnqueueTask(Action unit) { 55 protected void EnqueueTask(Action unit) {
56 Debug.Assert(unit != null); 56 Debug.Assert(unit != null);
57 var len = Interlocked.Increment(ref m_queueLength); 57 var len = Interlocked.Increment(ref m_queueLength);
58 m_queue.Enqueue(unit); 58 m_queue.Enqueue(unit);
59 59
60 if(!ExtendPool()) 60 ExtendPool();
61 WakePool();
62 } 61 }
63 62
64 protected override bool ExtendPool() { 63 protected override bool ExtendPool() {
65 if (m_queueLength <= m_threshold*ThreadCount) 64 if (m_queueLength <= m_threshold*ActiveThreads)
66 // in this case we are in active thread and it request for additional workers 65 // in this case we are in active thread and it request for additional workers
67 // satisfy it only when queue is longer than threshold 66 // satisfy it only when queue is longer than threshold
68 return false; 67 return false;
69 return base.ExtendPool(); 68 return base.ExtendPool();
70 } 69 }
79 78
80 protected override void InvokeUnit(Action unit) { 79 protected override void InvokeUnit(Action unit) {
81 unit(); 80 unit();
82 } 81 }
83 82
84 protected override void Suspend() { 83 protected override bool Suspend() {
85 if (m_queueLength == 0) 84 if (m_queueLength == 0)
86 base.Suspend(); 85 return base.Suspend();
86 else
87 return true; // spin again without locks...
87 } 88 }
88 } 89 }
89 } 90 }