Exemplo n.º 1
0
        public void Tick()
        {
            if (CurrentProcess == null || CurrentProcess.Quanta == 0 || CurrentProcess == IdleProcess)
            {
                CurrentProcess = SwitchToNextProcess();
            }

            Stream codeStream  = GetMemoryStream(CurrentProcess.Code);
            var    codeReader  = new CodeReader(codeStream);
            var    instruction = codeReader[Ip];

            if (instruction != null)
            {
                Execute(instruction);
            }
            else
            {
                foreach (var page in CurrentProcess.PageTable)
                {
                    Ram.Free(page);
                }

                CurrentProcess.IsRunning = false;
                CurrentProcess           = null;
            }

            TickSleepTimer();
            ReadTerminal();
            WriteTerminal();

            TickCount++;
        }
Exemplo n.º 2
0
        public void TerminateProcess(uint pId, uint exitCode)
        {
            var process = _processes[pId];

            foreach (var page in process.PageTable)
            {
                Ram.Free(page);
            }

            process.ExitCode  = exitCode;
            process.IsRunning = false;
        }
Exemplo n.º 3
0
        public void Exit(uint exitCode)
        {
            CurrentProcess.ExitCode  = exitCode;
            CurrentProcess.IsRunning = false;

            foreach (var page in CurrentProcess.PageTable)
            {
                Ram.Free(page);
            }

            CurrentProcess = null;
        }
Exemplo n.º 4
0
        public void Free(uint offset)
        {
            var page = CurrentProcess.PageTable.Find(x => x.Offset == offset);

            if (page != null)
            {
                foreach (var p in page.Pages)
                {
                    Ram.Free(p);
                }

                CurrentProcess.PageTable.Free(page);
            }
        }
Exemplo n.º 5
0
        public void Free()
        {
            var ram = new Ram(2, 1);

            var pcb = new ProcessContextBlock { Id = 1 };
            var frame = ram.Allocate(pcb);
            Assert.That(frame, Is.Not.Null);

            frame = ram.Allocate(pcb);
            Assert.That(frame, Is.Not.Null);

            ram.Free(frame);

            frame = ram.Allocate(pcb);
            Assert.That(frame, Is.Not.Null);
        }