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

📄 oneshot.cpp

📁 LINUX 下的 NACHOS 系统 实现系统调度的算法功能
💻 CPP
字号:
// oneshot.cc //  Routines to emulate a hardware one-shot timer device.////      A one-shot hardware timer generates a CPU interrupt in X milliseconds.//      The interrupt will only occur once and not ever X milliseconds.//      This means it can be used for implementing time-slicing.////  Remember -- nothing in here is part of Nachos.  It is just//  an emulation for the hardware that Nachos is running on top of.////  DO NOT CHANGE -- part of the machine emulation//////  Adapted from NachOS' timer.cc.//#include "copyright.h"#include "oneshot.h"#include "system.h"//----------------------------------------------------------------------// OneShotHandler//      The actual function to handle the interrupt. Used because of//  problems with C++ and function pointers.////      "arg" is the parameter passed to the user specified handler.//----------------------------------------------------------------------static void OneShotHandler(int arg){  OneShot *p = (OneShot *)arg;  p->TimerExpired();}//----------------------------------------------------------------------// OneShot::OneShot//      Initialize a hardware timer device.  Save the place to call//  on each interrupt, and then arrange for the timer to start//  generating interrupts.////      "timerHandler" is the interrupt handler for the timer device.//    It is called with interrupts disabled every time the//    the timer expires.//      "callArg" is the parameter to be passed to the interrupt handler.//      "time" is the number of milliseconds until the interrupt//             should occur//----------------------------------------------------------------------OneShot::OneShot(){ }void OneShot::SetArg(VoidFunctionPtr timerHandler, int callArg, int time){  handler = timerHandler;  arg = callArg;   // schedule interrupt for the one shot timer device  interrupt->Schedule(OneShotHandler, (int)this, time, TimerInt);   // the above code makes a bad assumption that a pointer is the same  // size as an int.}OneShot::OneShot(VoidFunctionPtr timerHandler, int callArg, int time){  handler = timerHandler;  arg = callArg;   // schedule interrupt for the one shot timer device  interrupt->Schedule(OneShotHandler, (int)this, time, TimerInt);   // the above code makes a bad assumption that a pointer is the same  // size as an int.}//----------------------------------------------------------------------// OneShot::TimerExpired//      Routine to simulate the interrupt generated by the hardware //  timer device.  Invoke the interrupt handler.//----------------------------------------------------------------------void OneShot::TimerExpired() {  // invoke the Nachos interrupt handler for this device  (*handler)(arg);}

⌨️ 快捷键说明

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