Exemplo n.º 1
0
        private List <IThread> TryGetThread()
        {
            List <IThread> result = new List <IThread>();
            IThread        t      = null;

            while (true)
            {
                bool hasThread = _threads.TryPop(out t);

                if (!hasThread)
                {
                    if (_threadCount < _info.MaxWorkerThreads &&
                        result.Count < _queue.Count)
                    {
                        result.Add(NewThread());
                    }
                    break;
                }
                else// if (hasThread)
                {
                    if (t.IsStop)
                    {
                        t.Dispose();
                        continue;
                    }
                    else
                    {
                        result.Add(t);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Close the driver, its topology, and all processors.
        /// </summary>
        public void Dispose()
        {
            tokenSource.Cancel();
            threadTopology.Dispose();

            foreach (var k in inputs)
            {
                k.Value.Dispose();
            }

            foreach (var k in outputs)
            {
                k.Value.Dispose();
            }
        }
Exemplo n.º 3
0
 public void Dispose()
 {
     threadTopology.Dispose();
     (kafkaSupplier as MockKafkaSupplier)?.Destroy();
 }
Exemplo n.º 4
0
        private void Loop()
        {
            while (true)
            {
                //Debug.WriteLine(this);
                //adjust pool every 1 sec
                _event.WaitOne(1000 * _info.AdjustInterval);

                if (_queue.Count == 0)
                {
                    continue;
                }

                List <IThread> threads = TryGetThread();

                if (null == threads || threads.Count == 0)
                {
                    continue;
                }

                int i = 0;
                for (; i < threads.Count; i++)
                {
                    IWorkItem workItem;
                    bool      hasItem = false;

                    do
                    {
                        hasItem = _queue.TryPeek(out workItem);

                        if (hasItem && workItem.IsCancel)
                        {
                            bool dropCancel = _queue.TryDequeue(out workItem);
                            //Assert.IsTrue(dropCancel);
                            _handles.Remove(workItem.WaitHandle);
                            workItem.Result = new WorkResult {
                                Exception = new CancelException()
                            };
                        }
                        else
                        {
                            break;
                        }
                    } while (true);

                    if (!hasItem)
                    {
                        //we break even if following thread can get item, to keep stack order
                        break;
                    }

                    IThread t = threads[i];
                    if (t.IsStop)
                    {
                        t.Dispose();
                        continue;
                    }
                    else
                    {
                        _queue.TryDequeue(out workItem);
                        Debug.WriteLine("assign {0} to thread {1}", workItem.Name, threads[i].Id);
                        threads[i].WorkItem = workItem;
                    }
                }

                //push from back end, keep the stack order
                for (int j = threads.Count - 1; j >= i; j--)
                {
                    _threads.Push(threads[j]);
                }
            }
        }
 public void Dispose()
 {
     _process.Dispose();
     _thread.Dispose();
 }
Exemplo n.º 6
0
 public void Dispose()
 {
     IsRunning = false;
     threadTopology.Dispose();
     (kafkaSupplier as MockKafkaSupplier)?.Destroy();
 }