/// <summary> /// Removes and returns the top object in the queue /// </summary> /// <returns>Top ecb in queue</returns> public EventControlBlock DeQueue() { EventControlBlock newEvent = this.ecbs[0]; this.ecbs.RemoveAt(0); return(newEvent); }
/// <summary> /// Creates a new event and adds it to the event queue /// </summary> /// <param name="eType">Type of event to create</param> public void CreateAndAddEvent(EventType eType) { EventControlBlock ecb = new EventControlBlock(); ecb.Type = eType; ecb.Id = _idCounter; _idCounter++; //ecb.clockCycle = cc; this.AddEvent(ecb); }
/// <summary> /// Handles events and makes takes the corresponding actions /// </summary> /// <param name="ecb"></param> public void HandleEvent(EventControlBlock ecb) { switch (ecb.Type) { case EventType.ReleaseIO: //get the pcb from the ioscheduler ProcessControlBlock pcb = this.IoScheduler.GetPcb(ecb.PcbId); //move it back to the ready queue this.Scheduler.ReadyQueue.EnQueue(pcb); this.Gui.UpdateIoQueueLog(); this.Gui.UpdateReadyQueueLog(); //updateUI = true; break; case EventType.ContextSwitch: this.Scheduler.ContextSwitch(); this.Scheduler.UpdateReadyQueue(); //this.gui.UpdateCurrentPCBTable(this.cpu.currentPcb.ToString()); this.Gui.UpdateReadyQueueLog(); this.Gui.UpdateAllocatedMemoryLabel(this.AllocatedMemory); this.Gui.UpdateAvgWaitTime(this.GetAvgWaitTimes(), this.Scheduler.FinishedPcbs.Count); break; case EventType.NewShortestFirstPCB: //check if anything in the waiting queue should be moved into the ready queue if (this.Scheduler.WaitingQueue.Size > 0) { var toCheck = this.Scheduler.WaitingQueue.DeQueue(); while (this.UpdateQueues(toCheck) && this.Scheduler.WaitingQueue.Size > 0) { toCheck = this.Scheduler.WaitingQueue.DeQueue(); } } this.Gui.UpdateWaitingQueueLog(); break; case EventType.Done: this.UserInterrupt = true; break; } }
/// <summary> /// Increment io cycles of pcbs in scheduler /// </summary> public void StartIo() { if (this._ioDictionary.Count > 0) { //decrement the io queues based on setting foreach (KeyValuePair <string, ExecutionQueue> item in _ioDictionary) { ExecutionQueue q = item.Value; if (this._os.Settings.DecrementAllIo) { item.Value.SimIoAll(); } else { item.Value.SimIoTop(); } } //loop through one more time to check if any of the ios are ready. if they are create an event so // the cpu will catch it on the next cc foreach (KeyValuePair <string, ExecutionQueue> item in _ioDictionary) { ExecutionQueue q = item.Value; foreach (ProcessControlBlock p in q.Pcbs) { //create an event that the io is ready if (p.CurrentOperation.Cycles == 0) { EventControlBlock ecb = new EventControlBlock(); ecb.Type = EventType.ReleaseIO; ecb.PcbId = p.PId; ecb.IoType = p.CurrentOperation.IoType; //add the event to the list that the cpu will check this._os.InterruptProcessor.AddEvent(ecb); } } } } this._os.Gui.UpdateIoQueueCycles(); }
/// <summary> /// Add an event to the queue /// </summary> /// <param name="ecb">Ecb to add</param> public void AddEvent(EventControlBlock ecb) { this.EventQueue.EnQueue(ecb); }
/// <summary> /// Add an ecb to the queue /// </summary> /// <param name="ecb"></param> public void EnQueue(EventControlBlock ecb) { this.ecbs.Add(ecb); }