/// <summary> /// The simulation of time-consuming operations with data performed by OS, such as moving data between memories. /// Sets the OS on inactive (busy), sleeps for the preset delay time, then sets the OS back to active (idle). /// </summary> private static async Task SimulateHandling() { IsActive = false; OsStateChanged?.Invoke(OsState.Busy, new EventArgs()); await Task.Delay(DelayTime); IsActive = true; OsStateChanged?.Invoke(OsState.Idle, new EventArgs()); }
/// <summary> /// The initializing method of the OS. Can be called from outside the project to start the simulation. /// </summary> /// <param name="processCount">The number of processes to be run during the simulation.</param> /// <param name="commandsCount">The number of commands to be executed during the simulation.</param> /// <param name="ramFrames">The number of frames the RAM will be divided into. Initially all are free.</param> /// <param name="maxPagesPerProcess">The maximum number of pages the page table of a process can hold.</param> /// <param name="delayTime">The value in milliseconds used for simulating the OS handling data-heavy operations.</param> /// <param name="betweenOpsDelay">The value in milliseconds used for simulating the OS switching between commands. Also for easier tracking of the simulation.</param> public static async Task Run(int processCount = 8, int commandsCount = 48, int ramFrames = 8, int maxPagesPerProcess = 8, int delayTime = 1000, int betweenOpsDelay = 750) { IsActive = true; OsStateChanged?.Invoke(OsState.Idle, new EventArgs()); FreeRamFrames = ramFrames; TotalRamCapacity = ramFrames; DelayTime = delayTime; BetweenOpsDelayTime = betweenOpsDelay; RamFramesTable = new List <RamFrame>(); Counter.ResetCounter(); Generator generator = new Generator(); Processes = generator.GenerateProcesses(processCount, maxPagesPerProcess); RamFramesTable = generator.GenerateRamFrames(TotalRamCapacity); Commands = generator.GenerateCommands(commandsCount, processCount, Processes); await MMU.Run(Commands, Processes.AsReadOnly(), BetweenOpsDelayTime); OsStateChanged?.Invoke(OsState.Free, new EventArgs()); IsActive = false; }