/// <summary>Creates a new scheduler as part of this group.</summary>
        /// <returns>The new <see cref="TaskScheduler"/>.</returns>
        public TaskScheduler CreateScheduler()
        {
            var createdQueue = new RoundRobinTaskSchedulerQueue(this);

            lock (_queues) _queues.Add(createdQueue);
            return(createdQueue);
        }
 /// <summary>Notifies the ThreadPool that there's a new item to be executed.</summary>
 private void NotifyNewWorkItem()
 {
     ThreadPool.UnsafeQueueUserWorkItem(delegate(object _) {
         Task task = null;
         RoundRobinTaskSchedulerQueue queue = null;
         lock (this._queues)
         {
             foreach (int num in Enumerable.Range(this._nextQueue, this._queues.Count - this._nextQueue).Concat <int>(Enumerable.Range(0, this._nextQueue)))
             {
                 queue = this._queues[num];
                 Queue <Task> queue2 = queue._workItems;
                 if (queue2.Count > 0)
                 {
                     task            = queue2.Dequeue();
                     this._nextQueue = num;
                     if (queue._disposed && (queue2.Count == 0))
                     {
                         this.RemoveQueue_NeedsLock(queue);
                     }
                     break;
                 }
             }
             this._nextQueue = (this._nextQueue + 1) % this._queues.Count;
         }
         if (task != null)
         {
             queue.RunQueuedTask(task);
         }
     }, null);
 }
        /// <summary>Removes a scheduler from the group.</summary>
        /// <param name="queue">The scheduler to be removed.</param>
        private void RemoveQueue_NeedsLock(RoundRobinTaskSchedulerQueue queue)
        {
            int index = _queues.IndexOf(queue);

            if (_nextQueue >= index)
            {
                _nextQueue--;
            }
            _queues.RemoveAt(index);
        }
        /// <summary>Creates a new scheduler as part of this group.</summary>
        /// <returns>The new scheduler.</returns>
        public TaskScheduler CreateScheduler()
        {
            RoundRobinTaskSchedulerQueue item = new RoundRobinTaskSchedulerQueue(this);

            lock (this._queues)
            {
                this._queues.Add(item);
            }
            return(item);
        }
        /// <summary>Notifies the <see cref="ThreadPool"/> that there's a new item to be executed.</summary>
        private void NotifyNewWorkItem()
        {
            // Queue a processing delegate to the ThreadPool
            ThreadPool.UnsafeQueueUserWorkItem(_ =>
            {
                Task targetTask = null;
                RoundRobinTaskSchedulerQueue queueForTargetTask = null;
                lock (_queues)
                {
                    // Determine the order in which we'll search the schedulers for work
                    var searchOrder = Enumerable.Range(_nextQueue, _queues.Count - _nextQueue).Concat(Enumerable.Range(0, _nextQueue));

                    // Look for the next item to process
                    foreach (int i in searchOrder)
                    {
                        queueForTargetTask = _queues[i];
                        var items          = queueForTargetTask._workItems;
                        if (items.Count > 0)
                        {
                            targetTask = items.Dequeue();
                            _nextQueue = i;
                            if (queueForTargetTask._disposed && items.Count == 0)
                            {
                                RemoveQueue_NeedsLock(queueForTargetTask);
                            }
                            break;
                        }
                    }
                    _nextQueue = (_nextQueue + 1) % _queues.Count;
                }

                // If we found an item, run it
                if (targetTask != null)
                {
                    queueForTargetTask.RunQueuedTask(targetTask);
                }
            }, null);
        }
Esempio n. 6
0
 /// <summary>Removes a scheduler from the group.</summary>
 /// <param name="queue">The scheduler to be removed.</param>
 private void RemoveQueue_NeedsLock(RoundRobinTaskSchedulerQueue queue)
 {
     int index = _queues.IndexOf(queue);
     if (_nextQueue >= index) _nextQueue--;
     _queues.RemoveAt(index);
 }
Esempio n. 7
0
 /// <summary>Creates a new scheduler as part of this group.</summary>
 /// <returns>The new scheduler.</returns>
 public TaskScheduler CreateScheduler()
 {
     var createdQueue = new RoundRobinTaskSchedulerQueue(this);
     lock (_queues) _queues.Add(createdQueue);
     return createdQueue;
 }