private Job PredictAssignTask() { Job temp = null; if (Current != null) { temp = Current.Clone(); } if (ReadyList.Count() > 0) { // Assign a task if we dont have one if (temp == null) { temp = ReadyList.Peek().Clone(); } // Preempt the current task if the awaiting task's deadline is lower //else if (ReadyList.Peek().PriorityDeadline < Current.PriorityDeadline) else if (ReadyList.Peek().PriorityDeadline < temp.PriorityDeadline) { //ReadyList.Enqueue(Current); temp = ReadyList.Peek().Clone(); } } return(temp); }
private void ReleaseTasks(int currentCycle) { while (WaitingList.Count() > 0 && currentCycle >= WaitingList.Peek().Release) { ReadyList.Enqueue(WaitingList.Dequeue()); } }
public void ProcessorScheduling() { //开始进程调度 while (ReadyList.Count > 0) { RunningProcess = ReadyList[0]; lock (ReadyList) { ReadyList.RemoveAt(0); } Prompt($"当前运行进程为{RunningProcess.Name}\n"); ReadyDraw(ReadyList); RunningDraw(RunningProcess); RunningProcess.Run(); //一段很不好的等待方法,很粗暴 DateTime now = DateTime.Now; DateTime end = now.AddSeconds(2); do { } while((DateTime.Now - end).Seconds < 0); if (RunningProcess.state == STATE.FINISH) { FinishedList.Add(RunningProcess); Prompt($"进程{RunningProcess.Name}运行结束\n"); RunningProcess = null; FinishedDraw(FinishedList); RunningDraw(RunningProcess); } else { lock (ReadyList) { ReadyList.Add(RunningProcess); ReadyList = SortListByPriority(ReadyList); } Prompt($"进程{RunningProcess.Name}重新插入到就绪队列\n"); Prompt($"当前优先数为{RunningProcess.priority},剩余运行时间为{RunningProcess.requestTime}\n"); RunningProcess = null; ReadyDraw(ReadyList); RunningDraw(RunningProcess); } //一段很不好的等待方法,很粗暴 now = DateTime.Now; end = now.AddSeconds(2); do { } while((DateTime.Now - end).Seconds < 0); } Prompt("就绪队列为空,所有进程运行结束\n"); }
public void AddReadyProcess(string name, int priority, int time) { Process p = new Process(name, priority, time); lock (ReadyList) { ReadyList.Add(p); ReadyList = SortListByPriority(ReadyList); } Prompt($"进程{name}加入就绪队列\n"); ReadyDraw(ReadyList); }
private void AssignTask() { if (ReadyList.Count() > 0) { // Assign a task if we dont have one if (Current == null) { Current = ReadyList.Dequeue(); } // Preempt the current task if the awaiting task's deadline is lower //else if (ReadyList.Peek().PriorityDeadline < Current.PriorityDeadline) else if (ReadyList.Peek().PriorityDeadline < Current.PriorityDeadline) { ReadyList.Enqueue(Current); Current = ReadyList.Dequeue(); } } }
public void Execute(DateTime StartTime) { if (ReadyList.Count == 0) //Prompt warning { System.Windows.MessageBox.Show("No ready tasks to be executed!"); return; } //Int32 count = ReadyList.Count; RequestedSubProgramClass[] ReadyArray = ReadyList.ToArray(); foreach (var RequestedSubProgram in ReadyArray) { //RequestedSubProgramClass RequestedSubProgram = ReadyList[i]; //ExecutorClass validExecutor = RequestedSubProgram.TopWaitingRequestedRecipe.ValidExecutor; foreach (var RequestedRecipe in RequestedSubProgram.RequestedRecipes) { if (RequestedRecipe.ValidExecutor.Status == ExecutorStatus.Ready) { RequestedRecipe.ValidExecutor.Execute(StartTime); } } } }
private void CounterEllapsed(Transportation source) { ReadyList.Add(source); WaitingList.Remove(source); }
private void btn_all_Click(object sender, RoutedEventArgs e) { ReadyList.SelectAll(); }
private void Executor_StatusChanged(object sender, EventArgs e) { try { ExecutorClass Executor = (ExecutorClass)sender; RequestedSubProgramClass root = Executor.RequestedRecipe.RequestedSubProgram; switch (Executor.Status) { case ExecutorStatus.Ready: WaitingList.Remove(root); ReadyList.Add(root); break; case ExecutorStatus.Executing: ReadyList.Remove(root); RunningList.Add(root); break; case ExecutorStatus.Completed: RunningList.Remove(root); if (root.RequestedRecipes.Count == 1) { CompletedList.Add(root); } else if (root.RequestedRecipes.Count > 1) { WaitingList.Insert(0, root); } break; case ExecutorStatus.Abandoned: if (ReadyList.Contains(root)) { ReadyList.Remove(root); } else if (WaitingList.Contains(root)) { WaitingList.Remove(root); } else if (RunningList.Contains(root)) { RunningList.Remove(root); } else if (CompletedList.Contains(root)) { CompletedList.Remove(root); } break; case ExecutorStatus.Invalid: Executor.RequestedRecipe.AddExecutor(); if (CompletedList.Contains(root)) { CompletedList.Remove(root); WaitingList.Insert(0, root); //back to the top by default } else if (RunningList.Contains(root)) { RunningList.Remove(root); WaitingList.Insert(0, root); //back to the top by default } break; } } catch { //sender is not a ExecutorClass type return; } }
//TODO: Does this work correctly with an empty taskset? /// <summary> /// This method executes the current event if is set. /// It also sets the upcoming event based on the readylist/waiting list. /// </summary> /// <param name="debug">Indicates if the ExecutionTrace should be built.</param> public void TriggerEvent(bool debug) { int next = Int32.MaxValue; ReleaseTasks(Event.Cycle); if (Current == null) { if (ReadyList.Count() > 0) { if ((Event.Cycle % Hyperperiod) == 0) { int offset = Separation[ReadyList.Peek().Cil]; next = Event.Cycle + offset; } else { Current = ReadyList.Dequeue(); next = Current.NextEvent(Event.Cycle, MacroTick); } } else if (WaitingList.Count() > 0) { next = WaitingList.Peek().Release; } } else { bool finalExecutionSlice = Current.FinalEvent(MacroTick); Current.Execute(Event.Cycle, debug, MacroTick); next = Current.NextEvent(Event.Cycle, MacroTick); int offset = 0; if (ReadyList.Count() > 0) { Job possibleJob = ReadyList.Peek(); if (possibleJob.Cil != Current.Cil) { offset = Separation[possibleJob.Cil]; } if (finalExecutionSlice) { WaitingList.Enqueue(Current); Current = null; next = Event.Cycle + offset; } else if ((possibleJob.PriorityDeadline + offset) < Current.PriorityDeadline) { ReadyList.Enqueue(Current); Current = null; next = Event.Cycle + offset; } } else { if (finalExecutionSlice) { WaitingList.Enqueue(Current); Current = null; foreach (var item in Separation) { if (offset < item.Value) { offset = item.Value; } } next = Event.Cycle + offset; } } ReleaseTasks(Event.Cycle); } Event.Cycle = next; }