示例#1
0
        public async Task RunScheduleAsync(TParam param, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (IsDirty)
            {
                _graph = new SchedulerGraph <T>(Tasks, Rules);
            }

            cancellationToken.ThrowIfCancellationRequested();

            var graphCopy = new SchedulerGraph <T>(_graph);
            var graphLock = new SemaphoreSlim(1);

            await Task.WhenAll(graphCopy.GetPendingTasks().Select(x => RunTask(x, param, graphCopy, graphLock, cancellationToken)));
        }
示例#2
0
        private async Task RunTask(int currentTask, TParam param, SchedulerGraph <T> graph, SemaphoreSlim graphLock, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            await _awaitableSelector(Tasks[currentTask], param, cancellationToken);

            int[] nextTasks;
            await graphLock.WaitAsync(cancellationToken);

            try
            {
                nextTasks = graph.GetNextTasks(currentTask).ToArray();
            }
            finally
            {
                graphLock.Release();
            }

            await Task.WhenAll(nextTasks.Select(x => RunTask(x, param, graph, graphLock, cancellationToken)));
        }
示例#3
0
        private void UpdateSchedule()
        {
            _schedule.Clear();
            _schedule.Capacity = Tasks.Count;

            var graph = new SchedulerGraph <T>(Tasks, Rules);

            var pendingTasks = new Queue <int>(graph.GetPendingTasks());

            while (pendingTasks.Count > 0)
            {
                int currentTask = pendingTasks.Dequeue();

                _schedule.Add(Tasks[currentTask]);

                foreach (int nextTask in graph.GetNextTasks(currentTask))
                {
                    pendingTasks.Enqueue(nextTask);
                }
            }

            IsDirty = false;
        }
 protected override Controller CreateController(SchedulerGraph <T> .Vertex vertex)
 {
     return(new Controller(this, vertex));
 }
 public Controller(SchedulerBase <Controller, T> scheduler, SchedulerGraph <T> .Vertex vertex)
 {
     PriorityController = new PriorityController <Controller, T>(scheduler, vertex);
     RelativeController = new RelativeController <Controller, T>(scheduler, vertex);
 }