⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interrupt.java

📁 只是一个简单模拟操作系统
💻 JAVA
字号:
/* * Interrupt.java * * Created on 2006年3月16日, 下午8:02 * *Used to be middle module between CPU and ProcessManager *That is , it is the only way that CPU and ProcessManager communicates *  */package os.cpu;/** * * @author Vernkin */public class Interrupt {        /**Intreeupt Num**/    public final static int TIMEOUT_INTERRUPT = 10;    public final static int HALT_INTERRUPT = 11;    public final static int CPUFREE_INTERRUPT = 12;        public final static int PrintOut_INTERRUPT = 21;    public final static int ConsoleOut_INTERRUPT = 22;    public final static int ConsoleIn_INTERRUPT = 23;        private os.process.MyProcess p = null;    private int interrupt_num;        private boolean cpu;//true indicate CPU leave message    private boolean manager;//true indicates ProcessManger leave message        private static Interrupt it = new Interrupt();    /** Creates a new instance of Interrupt */    private Interrupt() {        //empty body    }        public static Interrupt getInstance(){        return it;    }        /**If can't work ,return false**/    public boolean cpuSetMeaasge(os.process.MyProcess p,int interrupt_num){        if(manager)             return false;        this.p = p;        this.interrupt_num = interrupt_num;        System.out.println("CPU Request");//        manager = false;        cpu = true;                return true;    }        public os.process.MyProcess cpuGetProcess(){        if(!manager)            return null;                cpu = false;        manager = false;        System.out.println("CPU GetProcess "+p);        os.process.MyProcess temp = p;        p = null;        return temp;          }        public boolean managerShouldToSet(){        return cpu && !manager;            }        public boolean managerSetMessage(os.process.MyProcess pp){        /**cpu not request//manager hava already set**/        if(!managerShouldToSet()){            System.out.println("Stop managerSetMessage add new process");            return false;        }                    p = pp;        System.out.println("manager Set Message "+p);        manager = true;        return true;    }        public os.process.MyProcess managerGetProcess(){        if(!cpu)            return null;        manager = false;        os.process.MyProcess temp = p;        p = null;        return temp;    }        public void managerNotAvailbleProcess(){        interrupt_num = Interrupt.CPUFREE_INTERRUPT;    }            public boolean isCPURequest(){        return cpu;    }            public int getInterruptNum(){        return interrupt_num;    }        public void rest(int millsec){        if(millsec<1000)            millsec = 1000;        try{            Thread.sleep(millsec);                  }catch(InterruptedException e){            System.out.println(e.getMessage());        }    }            public String getInterruptName(int interrupt){        if(interrupt == Interrupt.TIMEOUT_INTERRUPT)            return "Time Out Interrupt";        if(interrupt == Interrupt.HALT_INTERRUPT)            return "Halt Interrupt";        if(interrupt == Interrupt.ConsoleIn_INTERRUPT)            return "Console Input Interrupt";        if(interrupt == Interrupt.ConsoleOut_INTERRUPT)            return "Console Output Interrupt";        if(interrupt == Interrupt.PrintOut_INTERRUPT)            return "Printer Interrupt";                return "Unknown Interrupt";    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -