Ejemplo n.º 1
0
 public void RemoveFromMemory(PCB processData)
 {
     //tablica ramek do ktorych zostaly wpisane strony
     int[] frames = null;
     //przypisanie do nich wartosci
     for (int i = 0; i < ProcessPages.Count; i++)
     {
         if (ProcessPages[i].Id == processData.PID)
         {
             frames = ProcessPages[i].ReadFrameNumbers();
             ProcessPages.RemoveAt(i);
             break;
         }
     }
     //zabezpieczenie przed exceptionem
     if (frames != null)
     {
         //wprowadzenie zwolnionych ramek do listy wolnych ramek
         //oczyszczenie ramek w pamieci fizycznej
         foreach (var frame in frames)
         {
             _freeFramesList.AddToList(frame);
             //_physicalMemory.GetFrame(frame).ClearFrame();
         }
     }
     //usuniecie z kolejki procesu
     _fifoQueue.RemoveChoosenProcess(processData.PID);
     //usuniecie danych z pliku wymiany
     _exchangeFile.RemoveFromMemory(processData.PID);
 }
Ejemplo n.º 2
0
 static PCBList ready = new PCBList(); // 就绪进程队列
 static void InputFromFile(string fileName)
 {
     try
     {
         FileStream   fs = new FileStream(fileName, FileMode.Open);
         StreamReader sr = new StreamReader(fs);
         // 读取进程数
         int      n = Convert.ToInt32(sr.ReadLine());
         string[] pcbInfo;
         // 依次读取每个进程
         for (int i = 0; i < n; i++)
         {
             pcbInfo = sr.ReadLine().Split(' ');
             // 建立、初始化PCB
             PCB pcb = new PCB();
             pcb.name     = pcbInfo[0];
             pcb.state    = State.ready;
             pcb.priority = Convert.ToInt32(pcbInfo[1]);
             pcb.needTime = Convert.ToInt32(pcbInfo[2]);
             pcb.runTime  = 0;
             pcb.next     = null;
             // 将新PCB插入就绪队列
             ready.Insert(pcb);
         }
         sr.Close();
         fs.Close();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Ejemplo n.º 3
0
        public void Check_JumpInstruction()
        {
            int    ordersCount   = 6;
            string memoryContent = "AD C,1\n" +
                                   "AD A,4\n" +
                                   "Etykieta:\n" +
                                   "MU A,2\n" +
                                   "JM Etykieta\n" +
                                   "HLT";

            var pcb = new PCB("testowy_jmInstruction", 5)
            {
                State = ProcessState.Running
            };

            Scheduler.GetInstance.AddProcess(pcb);
            Memory.GetInstance.AllocateMemory(pcb, memoryContent);

            for (int i = 0; i < ordersCount; i++)
            {
                Interpreter.GetInstance.InterpretOrder();
            }
            Scheduler.GetInstance.RemoveProcess(pcb);
            Assert.AreEqual(CentralProcessingUnit.GetInstance.Register.A, 8);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            InputFromFile("pcblist.txt"); // 从pcblist.txt读入待调度进程信息
            // 模拟调度
            int timeSlice = 0;            // 时间片计数

            while (ready.Count != 0)      // 就绪队列非空
            {
                timeSlice++;              // 轮转下一个时间片
                Console.WriteLine("运行时间片{0}", timeSlice);
                // 从就绪队列摘取队首进程(优先数最高)运行
                PCB currentPCB = ready.GetFirst();
                Run(currentPCB);
                Console.WriteLine("当前运行进程信息:");
                Console.WriteLine(currentPCB);
                Console.WriteLine("就绪队列列表:");
                ready.PrintList();
                if (currentPCB.state == State.finish)
                {
                    Console.WriteLine("进程{0}执行完毕", currentPCB.name);
                }
                else
                {
                    ready.Insert(currentPCB);
                }
                Console.WriteLine("按任意键继续");
                Console.ReadKey();
            }
            Console.WriteLine("所有进程执行完毕");
        }
Ejemplo n.º 5
0
        public static String registerLink(PCB pcb, Dictionary <string, string> initialConfig, String sqlConnection)
        {
            try
            {
                DataSet dsGetLoops = new DataSet();

                //Registers the link in the local database
                insertPalletLink(pcb, initialConfig, sqlConnection);

                //Update or insert the loop count
                dsGetLoops = getLoopsNumber(pcb, sqlConnection);

                if (!(dsGetLoops.Tables[0].Rows.Count > 0))
                {
                    initialConfig.Add("loopsNumber", "1");
                    insertBoardLoopsCounter(pcb, initialConfig, sqlConnection);
                    return("OK");
                }

                initialConfig.Add("PKBoardLoopCounter", dsGetLoops.Tables[0].Rows[0]["PKBoardLoopCounter"].ToString());
                initialConfig.Add("loopsNumber", dsGetLoops.Tables[0].Rows[0]["LoopsNumber"].ToString());
                updateBoardLoopsCounter(pcb, initialConfig, sqlConnection);

                return("OK");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Ejemplo n.º 6
0
        public void Get_GetOrderFromMemory()
        {
            string memoryContent = "AD A,4\n" +
                                   "MV A,B\n" +
                                   "MF NowyPlik\n" +
                                   "WR NowyPlik,A\n" +
                                   "Etykieta:\n" +
                                   "HLT";
            string resultOrder = String.Empty;

            var pcb = new PCB("testowy_getOrder", 5);

            Memory.GetInstance.AllocateMemory(pcb, memoryContent);

            resultOrder = Interpreter.GetInstance.GetOrderFromMemory(pcb);
            Assert.IsTrue(resultOrder == "AD A,4");

            resultOrder = Interpreter.GetInstance.GetOrderFromMemory(pcb);
            Assert.IsTrue(resultOrder == "MV A,B");

            resultOrder = Interpreter.GetInstance.GetOrderFromMemory(pcb);
            Assert.IsTrue(resultOrder == "MF NowyPlik");

            resultOrder = Interpreter.GetInstance.GetOrderFromMemory(pcb);
            Assert.IsTrue(resultOrder == "WR NowyPlik,A");

            resultOrder = Interpreter.GetInstance.GetOrderFromMemory(pcb);
            Assert.IsTrue(resultOrder == "Etykieta:");

            resultOrder = Interpreter.GetInstance.GetOrderFromMemory(pcb);
            Assert.IsTrue(resultOrder == "HLT");

            resultOrder = Interpreter.GetInstance.GetOrderFromMemory(pcb);
            Assert.IsTrue(resultOrder == "");
        }
Ejemplo n.º 7
0
        public void Check_GetRunningPCB()
        {
            var scheduler = Scheduler.GetInstance;
            var pcb1      = new PCB("first_grpcb", 4);
            var pcb2      = new PCB("second_grpcb", 3);
            var pcb3      = new PCB("third_grpcb", 7);
            var pcb4      = new PCB("last_grpcb", 1)
            {
                State = ProcessState.Running
            };
            var pcb5 = new PCB("latest_grpcb", 5);

            scheduler.AddProcess(pcb1);
            scheduler.AddProcess(pcb2);
            scheduler.AddProcess(pcb3);
            scheduler.AddProcess(pcb4);
            scheduler.AddProcess(pcb5);

            Assert.AreEqual(scheduler.GetRunningPCB(), pcb4);

            scheduler.RemoveProcess(pcb1);
            scheduler.RemoveProcess(pcb2);
            scheduler.RemoveProcess(pcb3);
            scheduler.RemoveProcess(pcb4);
            scheduler.RemoveProcess(pcb5);
        }
Ejemplo n.º 8
0
        public void PCB_CheckEquatable(string firstName, int firstPriority, string secondName, int secondPriority)
        {
            var firstPcb  = new PCB(firstName, firstPriority);
            var secondPcb = new PCB(secondName, secondPriority);

            Assert.IsTrue(firstPcb.Equals(secondPcb));
        }
Ejemplo n.º 9
0
        public bool XA(ref PCB pcb)
        {
            int ile_komórek_potrzeba = pcb.Auto_storage_size;

            int ile_ramek = ile_potrzeba_ramek(pcb.Auto_storage_size); //w ilu ramek w sumie program zajmie

            ile_ramek += ile_potrzeba_ramek(pcb.Auto_data_size);
            ile_ramek += ile_potrzeba_ramek(pcb.Auto_stack_size);
            int ile_należy_się_ramek   = ile_ramek_przydzielić(ile_ramek); //ile ramek się programowi nalezy zgodnie z przydziałem proporcjonalnym
            int ile_należy_się_stronic = ile_ramek - ile_należy_się_ramek; //jezeli jest wymaganych więcej ramek niż proporcjonalnie może dostać proces, pozostałe ramki zostaną przesunięte do pamięci wirtualnej

            if (ile_ramek <= wolne_ramki.Count + wolne_stronice.Count)     //jeżeli starczy ramek (uwzględniając przenoszenie do stronic) na proces to alokuję pamięć
            {
                przydziel_pamięć_programowi(ref pcb);

                return(true);
            }
            else if (ile_ramek > tablica_ramek.Count + tablica_stronnic.Count)
            {
                Exception a = new Exception();
                throw a;
            }
            else
            {
                memory.P(ref pcb);

                return(false);
            }
        }
Ejemplo n.º 10
0
        public void XNOrder(string processName)
        {
            Console.WriteLine("Rozkaz XN z parametrem " + processName);

            var pcbID = PCB.GetPCB(processName).PID;

            CPU.GetInstance.Register.SetRegisterValueByName("A", pcbID);
        }
Ejemplo n.º 11
0
            // 摘取就绪队列首结点
            public PCB GetFirst()
            {
                PCB pcb = head;

                head     = head.next;
                pcb.next = null;
                count--;
                return(pcb);
            }
Ejemplo n.º 12
0
        private string getFinalResult(PCB pcb, Dictionary <int, PCB> unitsInPanelOK)
        {
            //Falta devolver 2 datos, checar si en verdad es necesario devolverlos.
            //Ambos datos indican si la pieza viene panelizada.

            JObject json = new JObject();

            json.Add("serialNumbers", JObject.FromObject(unitsInPanelOK));
            return(json.ToString());
        }
Ejemplo n.º 13
0
        public void P(ref PCB pcb)
        {
            wartość--;

            pcb.Blocked = true;

            oczekujące.Enqueue(pcb);


            Console.WriteLine("Dodano proces na semafor oczekujących!");
        }
Ejemplo n.º 14
0
            public void PrintList()
            {
                // 输出就绪队列里所有结点的信息
                PCB current = head;

                while (current != null)
                {
                    Console.WriteLine(current.ToString());
                    current = current.next;
                }
            }
Ejemplo n.º 15
0
        private void getPalletTimeOut(PCB pcb)
        {
            DataSet dataSet = new DataSet();

            dataSet = PCBQueryService.getCustomerTimeOut(initialConfig["customerID"], sqlConnectionPL);

            if (dataSet.Tables[0].Rows.Count > 0)
            {
                initialConfig.Add("palletTimeOut", dataSet.Tables[0].Rows[0]["TimeOut"].ToString());
            }
            initialConfig.Add("palletTimeOut", "120");
        }
Ejemplo n.º 16
0
        public void Can_Add_Data_To_Empty_Memory(string input, int index, char output)
        {
            //prepare
            var pcb = new PCB();

            //action
            Memory.GetInstance.AllocateMemory(pcb, input);
            var data = pcb.MemoryBlocks.ReadByte(index);

            //assetrion
            Assert.AreEqual(data, output);
        }
Ejemplo n.º 17
0
        public PCB V()
        {
            wartość++;

            Console.WriteLine("Zdjęto proces z semaforu, nastąpi próba alokacji pamięci!");

            PCB pcb = oczekujące.Dequeue();

            pcb.Blocked = false;

            return(pcb);
        }
Ejemplo n.º 18
0
        public void XDOrder(string processName)
        {
            Console.WriteLine("Rozkaz XD z parametrem " + processName);

            var flag = PCB.GetPCB(processName).TerminateProcess(ReasonOfProcessTerminating.KilledByOther,
                                                                Scheduler.GetInstance.GetRunningPCB());

            if (flag == 0)
            {
                PCB.GetPCB(processName).RemoveProcess();
            }
        }
        public ChanelSelectWindow(string path, Window startupWindow)
        {
            _codeclosing   = false;
            _startupWindow = startupWindow;
            Connections    = new List <ConnectionUnion>();
            InitializeComponent();
            Title = ApplicationSettings.Name;
            MyWindow.SizeChanged += MyWindowOnSizeChanged;

            var parser = new AltiumParser.AltiumParser(path);
            var type   = GetPsbType(parser);

            switch (type)
            {
            case PcbTypes.EttNew:
                pcb         = new NewEttBoard(parser);
                Connections = pcb.Connections;
                break;

            case PcbTypes.EttOld:
                pcb         = new OldEttBoard(parser);
                Connections = pcb.Connections;
                break;

            case PcbTypes.F2kNew:
                pcb         = new NewF2KBoard(parser);
                Connections = pcb.Connections;
                break;
            }

            foreach (var connection in Connections)
            {
                Console.WriteLine(connection);
            }

            ConnectionList.ItemsSource       = Connections;
            ConnectionList.SelectionChanged += ConnectionListOnSelectionChanged;

            var counter = 0;

            foreach (var connection in Connections)
            {
                counter += connection.Chanels.Count;
            }
            PCBInfo     = "Плата " + Path.GetFileName(parser.FilePath)?.Replace(".SchDoc", "") + " || " + counter + " Каналов";
            Report.Text = PCBInfo;

            if (pcb.GetType() == typeof(NewEttBoard) || pcb.GetType() == typeof(OldEttBoard))
            {
                var temppcb = (EttPCB)pcb;
                Report.Text += " || " + temppcb.DutCount + " DUTs";
            }
        }
Ejemplo n.º 20
0
        private void RetPCB(PCB pcb)
        {
            lock (this)
            {
                if (pcb == null)
                {
                    return;
                }

                _IdleThreadQueue.Enqueue(pcb.ThreadId);
            }
        }
Ejemplo n.º 21
0
    /// <summary>
    /// Disconnect and retry the connecting to the SenseGlove,
    /// such as when a different glove is connected or when the (manual) connection is lost.
    /// </summary>
    public void RetryConnection()
    {
        this.Disconnect();
        if (this.connectionMethod != ConnectionMethod.HardCoded)
        {
            if (!SenseGloveCs.DeviceScanner.IsScanning())
            {
                SenseGloveCs.DeviceScanner.pingTime  = 200;
                SenseGloveCs.DeviceScanner.scanDelay = 500;
                SenseGloveCs.DeviceScanner.StartScanning(true);
            }
        }
        else //we're dealing with a custom connection!
        {
            if (canReport)
            {
                SenseGlove_Debugger.Log("Attempting to connect to " + this.address);
            }
            Communicator PCB = null;
            if (this.address.Contains("COM")) //Serial connections
            {
                if (this.address.Length > 4 && this.address.Length < 6)
                {
                    this.address = "\\\\.\\" + this.address;
                }
                PCB = new SerialCommunicator(this.address);
            }
            if (PCB != null)
            {
                PCB.Connect();
                if (PCB.IsConnected())
                {
                    this.glove = new SenseGlove(PCB);
                    this.glove.OnFingerCalibrationFinished += Glove_OnFingerCalibrationFinished;
                }
                else if (canReport)
                {
                    SenseGlove_Debugger.Log("ERROR: Could not connect to " + this.address);
                    canReport = false;
                }
            }
            else if (canReport)
            {
                SenseGlove_Debugger.Log("ERROR: " + this.address + " is not a valid address.");
                canReport = false;
            }
        }


        this.elapsedTime = 0;
        this.standBy     = false;
    }
Ejemplo n.º 22
0
        private LinkingLog prepareLog(PCB pcb, DataSet logData)
        {
            LinkingLog log = new LinkingLog();

            log.pcb          = pcb;
            log.palletID     = palletID;
            log.palletSerial = palletSerial;
            if (logData != null && logData.Tables[0].Rows.Count > 0)
            {
                log.loopsAllowed = logData.Tables[0].Rows[0]["LoopsAllowed"].ToString();
            }
            return(log);
        }
Ejemplo n.º 23
0
        public void Can_Read_Data_From_Memory(int index, char output)
        {
            //prepare
            var pcb = new PCB();

            Memory.GetInstance.TestFillMemory(pcb);

            //action
            var data = pcb.MemoryBlocks.ReadByte(index);

            //assertion
            Assert.AreEqual(data, output);
        }
Ejemplo n.º 24
0
        private void ListenForClients()
        {
            try
            {
                this._TcpListener.Start();

                while (true)
                {
                    //blocks until a client has connected to the server
                    System.Net.Sockets.TcpClient client = this._TcpListener.AcceptTcpClient();

                    try
                    {
                        //create a thread to handle communication
                        //with connected client
                        Thread clientThread =
                            new Thread(new
                                       ParameterizedThreadStart(HandleClientComm));

                        clientThread.IsBackground = true;

                        PCB pcb = GetPCB(client);

                        if (pcb == null)
                        {
                            //Over max connect number
                            ReturnMessage(client, client, new MessageHead(), new Exception("Too many connects on server"), null);

                            System.Threading.Thread.Sleep(200);

                            client.Close();
                            throw new Exception("Too many connects on server");
                        }
                        else
                        {
                            clientThread.Start(pcb);
                        }
                    }
                    catch (Exception e)
                    {
                        OnMessageReceiveErrorEvent(new MessageReceiveErrorEventArgs(e));
                    }
                }
            }
            catch (Exception e)
            {
                OnMessageReceiveErrorEvent(new MessageReceiveErrorEventArgs(e));
            }
        }
Ejemplo n.º 25
0
        public bool XF(ref PCB pcb)
        {
            zwolnij_przydzieloną_pamięć_programowi(pcb.Auto_storage_addres, pcb.Auto_storage_size);
            int wartość_semafora_memory = memory.getWartość;

            if (wartość_semafora_memory < 0)
            {
                for (int i = wartość_semafora_memory; i < 0; i++)
                {
                    PCB bufor = memory.V();
                    XA(ref bufor);
                }
            }
            return(true);
        }
Ejemplo n.º 26
0
        private PCB GetPCB(System.Net.Sockets.TcpClient client)
        {
            lock (this)
            {
                if (_IdleThreadQueue.Count == 0)
                {
                    return(null);
                }

                int id  = _IdleThreadQueue.Dequeue();
                PCB pcb = new PCB();
                pcb.ThreadId = id;
                pcb.Client   = client;
                return(pcb);
            }
        }
Ejemplo n.º 27
0
        private static void updateBoardLoopsCounter(PCB pcb, Dictionary <string, string> initialConfig, string sqlConnection)
        {
            using (SqlConnection connection = new SqlConnection(sqlConnection))
                using (SqlCommand command = new SqlCommand("up_UpdSerialLoopsCounter", connection)
                {
                    CommandType = CommandType.StoredProcedure
                })
                {
                    connection.Open();
                    command.Parameters.AddWithValue("@PKBoardLoopCounter", Convert.ToInt32(initialConfig["PKBoardLoopCounter"]));
                    command.Parameters.AddWithValue("@LoopsNumber", Convert.ToInt32(initialConfig["loopsNumber"]));
                    command.Parameters.AddWithValue("@Userupdated ", initialConfig["userName"]);

                    command.ExecuteNonQuery();
                }
        }
Ejemplo n.º 28
0
        static void Main(string[] args)
        {
            Computer a = new PCA();

            Console.WriteLine(" a is a computer type A , cup is {0},  viedocar is {1}", a.getcpu(), a.videocard);
            a = new PCB();
            Console.WriteLine(" a is a computer type B, cup is {0},  viedocar is {1}", a.getcpu(), a.videocard);
            //a.videocard = "sfsdf"; wrong, for computer videocard  not set

            PCB b = new PCB();

            b.videocard = "Nvida 3400";
            // Correct ,
            //a.videocard = "sfsdf"; wrong, for computer videocard  not set
            Console.WriteLine(" b is a computer type B, cup is {0},  viedocar is {1}", b.getcpu(), b.videocard);
        }
Ejemplo n.º 29
0
        public void Can_Change_Data(string input, int index, char change)
        {
            //prepare
            var pcbfiller = new PCB();
            var pcb       = new PCB();

            Memory.GetInstance.AllocateMemory(pcb, input);

            //aciton
            pcb.MemoryBlocks.ChangeByte(index, change);
            Memory.GetInstance.TestFillMemory(pcbfiller);
            var data = pcb.MemoryBlocks.ReadByte(index);

            //assertion
            Assert.AreEqual(data, change);
        }
Ejemplo n.º 30
0
 // 执行pcb进程一个时间片,执行完后,修改pcb
 static void Run(PCB pcb)
 {
     // 执行完一个时间片后,优先数-1
     pcb.priority--;
     // 已执行时间+1
     pcb.runTime++;
     if (pcb.runTime == pcb.needTime)
     {
         // 如果已执行时间等于进程执行所需时间,进程执行完毕
         pcb.state = State.finish;
     }
     else
     {
         // 还没执行完,需要将pcb重新插入就绪队列
         pcb.state = State.ready;
     }
 }
Ejemplo n.º 31
0
 public Module(Compound parent, string name, Vector3D pos, double rot)
     : base(parent, name, pos, rot)
 {
     PCB = null;
 }