コード例 #1
0
        private void CompleteWork(int workerId)
        {
            lock (syncRoot)
            {
                busyWorkers = busyWorkers.Remove(workerId);
                idleWorkers = idleWorkers.Add(workerId);

                if (waitingWorkItems.Count > 0)
                {
                    WaitingWorkItem wwi = waitingWorkItems.Dequeue();

                    if (wwi.work is Func <int, Task> )
                    {
                        wwi.k.PostResult(StartWorker((Func <int, Task>)wwi.work));
                    }
                    else
                    {
                        wwi.k.PostResult(StartWorker((Func <int, CancellationToken, Task>)wwi.work, wwi.ctoken));
                    }

                    if (wwi.ctr.HasValue)
                    {
                        wwi.ctr.Value.Dispose();
                    }
                }
            }
        }
コード例 #2
0
        public void Leave()
        {
            lock (syncRoot)
            {
                --referenceCount;

                if (referenceCount == 0)
                {
                    while (waiters.Count > 0)
                    {
                        Waiter waiter = waiters.Dequeue();

                        waiter.k.PostResult(true);

                        if (waiter.ctr.HasValue)
                        {
                            waiter.ctr.Value.Dispose();
                        }
                    }
                }
            }
        }