示例#1
0
文件: Cpu.cs 项目: andy-uq/TinyOS
        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++;
        }
示例#2
0
文件: Cpu.cs 项目: andy-uq/TinyOS
        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;
        }
示例#3
0
文件: Cpu.cs 项目: andy-uq/TinyOS
        public void Exit(uint exitCode)
        {
            CurrentProcess.ExitCode  = exitCode;
            CurrentProcess.IsRunning = false;

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

            CurrentProcess = null;
        }
示例#4
0
文件: Cpu.cs 项目: andy-uq/TinyOS
        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);
            }
        }
示例#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);
        }