예제 #1
0
        public void Schedule(Task task)
        {
            //Unfortunatelly this can happen, who knows why
            if (task.Item.Work == null)
            {
                return;
            }

            WorkPriority priority = WorkPriority.Normal;

            {
                var prioritizedWork = task.Item.Work as IPrioritizedWork;
                if (prioritizedWork != null)
                {
                    priority = prioritizedWork.Priority;
                }
            }
            m_taskQueuesByPriority[(int)priority].Enqueue(task);
            Interlocked.Increment(ref m_scheduledTaskCount);

            foreach (var worker in m_workers)
            {
                worker.Gate.Set();
            }
        }
예제 #2
0
            /// <summary>
            /// Schedule the task in this worker array.
            /// </summary>
            /// <param name="task"></param>
            /// <param name="priority"></param>
            public void Schedule(Task task, WorkPriority priority)
            {
                m_taskQueuesByPriority[(int)priority].Enqueue(task);
                Interlocked.Increment(ref m_scheduledTaskCount);

                foreach (var worker in m_workers)
                {
                    worker.Gate.Set();
                }
            }
        public void ChangeItemPriority(PriorityItem <T> item, WorkPriority priority) // NOTE: should be Priority
        {
            // Remove the item from its current priority and insert it into
            // the new priority chain.  Note that this does not change the
            // sequential ordering.

            // Step 1: Remove the item from the priority chain.
            RemoveItemFromPriorityChain(item);

            // Step 2: Insert the item into the new priority chain.
            // Find the existing chain for this priority, or create a new one
            // if one does not exist.
            PriorityChain <T> chain = GetChain(priority);

            InsertItemInPriorityChain(item, chain);
        }
        public PriorityItem <T> Enqueue(WorkPriority priority, T data) // NOTE: should be Priority
        {
            // Find the existing chain for this priority, or create a new one
            // if one does not exist.
            PriorityChain <T> chain = GetChain(priority);

            // Wrap the item in a PriorityItem so we can put it in our
            // linked list.
            PriorityItem <T> priorityItem = new PriorityItem <T>(data);

            // Step 1: Append this to the end of the "sequential" linked list.
            InsertItemInSequentialChain(priorityItem, _tail);

            // Step 2: Append the item into the priority chain.
            InsertItemInPriorityChain(priorityItem, chain, chain.Tail);

            return(priorityItem);
        }
예제 #5
0
        public void Schedule(Task task)
        {
            if (task.Item.Work == null)  // deny tasks with no content
            {
                return;
            }

            WorkPriority priority = WorkPriority.Normal;

            {
                var prioritizedWork = task.Item.Work as IPrioritizedWork;
                if (prioritizedWork != null)
                {
                    priority = prioritizedWork.Priority;
                }
            }
            GetWorkerArray(priority).Schedule(task, priority);
        }
예제 #6
0
        private PriorityChain <T> GetChain(WorkPriority priority)
        // NOTE: should be Priority
        {
            PriorityChain <T> chain = null;

            int count = _priorityChains.Count;

            if (count > 0)
            {
                if (priority == (WorkPriority)_priorityChains.Keys[0])
                {
                    chain = _priorityChains.Values[0];
                }
                else if (priority ==
                         (WorkPriority)_priorityChains.Keys[count - 1])
                {
                    chain = _priorityChains.Values[count - 1];
                }
                else if ((priority > (WorkPriority)_priorityChains.Keys[0]) &&
                         (priority < (WorkPriority)_priorityChains.Keys[count - 1]))
                {
                    _priorityChains.TryGetValue((int)priority, out chain);
                }
            }

            if (chain == null)
            {
                if (_cacheReusableChains.Count > 0)
                {
                    chain          = _cacheReusableChains.Pop();
                    chain.Priority = priority;
                }
                else
                {
                    chain = new PriorityChain <T>(priority);
                }

                _priorityChains.Add((int)priority, chain);
            }

            return(chain);
        }
 public PriorityChain(WorkPriority priority) // NOTE: should be Priority
 {
     _priority = priority;
 }
예제 #8
0
 private WorkerArray GetWorkerArray(WorkPriority priority)
 {
     return(m_workerArrays[m_mappingPriorityToWorker[(int)priority]]);
 }
예제 #9
0
 private WorkerArray GetWorkerArray(WorkPriority priority)
 {
     return m_workerArrays[m_mappingPriorityToWorker[(int)priority]];
 }
예제 #10
0
            /// <summary>
            /// Schedule the task in this worker array.
            /// </summary>
            /// <param name="task"></param>
            /// <param name="priority"></param>
            public void Schedule(Task task, WorkPriority priority)
            {
                m_taskQueuesByPriority[(int)priority].Enqueue(task);
                Interlocked.Increment(ref m_scheduledTaskCount);

                foreach (var worker in m_workers)
                    worker.Gate.Set();
            }
예제 #11
0
 /// <summary>
 /// 新增工作
 /// </summary>
 /// <param name="Work">工作</param>
 /// <param name="Priority">優先權</param>
 public void AddThreadWork(WorkItem Work,
                           WorkPriority Priority = WorkPriority.Normal)
 {
     lock (workQueueLock)
         workQueue.Enqueue(Priority, Work);
 }