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

📄 synchconsole.cc

📁 Nachos是个教学用的小型操作系统
💻 CC
字号:
// synchconsole.cc //	Routines providing synchronized access to the keyboard //	and console display hardware devices.//// Copyright (c) 1992-1996 The Regents of the University of California.// All rights reserved.  See copyright.h for copyright notice and limitation // of liability and disclaimer of warranty provisions.#include "copyright.h"#include "synchconsole.h"//----------------------------------------------------------------------// SynchConsoleInput::SynchConsoleInput//      Initialize synchronized access to the keyboard////      "inputFile" -- if NULL, use stdin as console device//              otherwise, read from this file//----------------------------------------------------------------------SynchConsoleInput::SynchConsoleInput(char *inputFile){    consoleInput = new ConsoleInput(inputFile, this);    lock = new Lock("console in");    waitFor = new Semaphore("console in", 0);}//----------------------------------------------------------------------// SynchConsoleInput::~SynchConsoleInput//      Deallocate data structures for synchronized access to the keyboard//----------------------------------------------------------------------SynchConsoleInput::~SynchConsoleInput(){     delete consoleInput;     delete lock;     delete waitFor;}//----------------------------------------------------------------------// SynchConsoleInput::GetChar//      Read a character typed at the keyboard, waiting if necessary.//----------------------------------------------------------------------charSynchConsoleInput::GetChar(){    char ch;    lock->Acquire();    waitFor->P();	// wait for EOF or a char to be available.    ch = consoleInput->GetChar();    lock->Release();    return ch;}//----------------------------------------------------------------------// SynchConsoleInput::CallBack//      Interrupt handler called when keystroke is hit; wake up//	anyone waiting.//----------------------------------------------------------------------voidSynchConsoleInput::CallBack(){    waitFor->V();}//----------------------------------------------------------------------// SynchConsoleOutput::SynchConsoleOutput//      Initialize synchronized access to the console display////      "outputFile" -- if NULL, use stdout as console device//              otherwise, read from this file//----------------------------------------------------------------------SynchConsoleOutput::SynchConsoleOutput(char *outputFile){    consoleOutput = new ConsoleOutput(outputFile, this);    lock = new Lock("console out");    waitFor = new Semaphore("console out", 0);}//----------------------------------------------------------------------// SynchConsoleOutput::~SynchConsoleOutput//      Deallocate data structures for synchronized access to the keyboard//----------------------------------------------------------------------SynchConsoleOutput::~SynchConsoleOutput(){     delete consoleOutput;     delete lock;     delete waitFor;}//----------------------------------------------------------------------// SynchConsoleOutput::PutChar//      Write a character to the console display, waiting if necessary.//----------------------------------------------------------------------voidSynchConsoleOutput::PutChar(char ch){    lock->Acquire();    consoleOutput->PutChar(ch);    waitFor->P();    lock->Release();}//----------------------------------------------------------------------// SynchConsoleOutput::CallBack//      Interrupt handler called when it's safe to send the next //	character can be sent to the display.//----------------------------------------------------------------------voidSynchConsoleOutput::CallBack(){    waitFor->V();}

⌨️ 快捷键说明

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