Main Page   Compound List   File List   Compound Members   File Members  

SynchConsole Class Reference

#include <synchconsole.h>

List of all members.

Public Methods

 SynchConsole (char *, char *)
 ~SynchConsole ()
void WriteDone ()
void ReadAvail ()
void WriteLine (char *, int)
int ReadLine (char *, int)

Private Attributes

LockinputMutex
LockoutputMutex
SemaphoreinputAvailable
SemaphoreoutputDone
Consoleconsole


Constructor & Destructor Documentation

SynchConsole::SynchConsole char *   ,
char *   
 

Definition at line 13 of file synchconsole.cc.

References ASSERT, console, inputAvailable, inputMutex, NULL, outputDone, outputMutex, SynchReadAvail, SynchWriteDone, and VoidFunctionPtr.

00014 { 
00015   inputMutex = new Lock("synchronized console input mutex");
00016   ASSERT(inputMutex != NULL);
00017   inputAvailable = new Semaphore("synchronized console input semaphore",0);
00018   ASSERT(inputAvailable != NULL);
00019   outputMutex = new Lock("synchronized console output mutex");
00020   ASSERT(outputMutex != NULL);
00021   outputDone = new Semaphore("synchronized console output semaphore", 0);
00022   ASSERT(outputDone != NULL);
00023    
00024   console = new Console(readFile, writeFile,
00025 (VoidFunctionPtr)SynchReadAvail, (VoidFunctionPtr)SynchWriteDone,(int) this);
00026 }

SynchConsole::~SynchConsole  
 

Definition at line 28 of file synchconsole.cc.

References console, inputAvailable, inputMutex, NULL, outputDone, and outputMutex.

00029 {
00030   delete inputMutex;
00031   inputMutex = NULL;
00032   delete outputMutex;
00033   outputMutex = NULL;
00034   delete inputAvailable;
00035   inputAvailable = NULL;
00036   delete outputDone;
00037   outputDone = NULL;
00038   delete console;
00039   console = 0;
00040 }


Member Function Documentation

void SynchConsole::ReadAvail  
 

Definition at line 6 of file synchconsole.cc.

References inputAvailable, and Semaphore::V.

Referenced by SynchReadAvail.

00006 { inputAvailable->V();}

int SynchConsole::ReadLine char *   ,
int   
 

Definition at line 56 of file synchconsole.cc.

References Lock::Acquire, console, DEBUG, Console::GetChar, inputAvailable, inputMutex, Semaphore::P, and Lock::Release.

00057 {
00058   char c = 0;
00059   int num_read = 0;
00060   inputMutex->Acquire();
00061   while (c != '\n' && num_read < size) {
00062       inputAvailable->P();
00063       c = console->GetChar();
00064       *line = c;
00065       line++; num_read++;
00066   }
00067   inputMutex->Release();
00068   DEBUG('r', "Read the %d character string %s into buffer of size %d\n",num_read, line-num_read, size);
00069   return num_read;
00070 }

void SynchConsole::WriteDone  
 

Definition at line 5 of file synchconsole.cc.

References outputDone, and Semaphore::V.

Referenced by SynchWriteDone.

00005 { outputDone->V();}

void SynchConsole::WriteLine char *   ,
int   
 

Definition at line 43 of file synchconsole.cc.

References Lock::Acquire, console, outputDone, outputMutex, Semaphore::P, Console::PutChar, and Lock::Release.

00044 {
00045   
00046   outputMutex->Acquire();
00047   while (size --) {
00048     console->PutChar(*line);
00049     line++;
00050     outputDone->P();
00051   }
00052   outputMutex->Release();
00053 }


Member Data Documentation

Console* SynchConsole::console [private]
 

Definition at line 24 of file synchconsole.h.

Referenced by ReadLine, SynchConsole, WriteLine, and ~SynchConsole.

Semaphore* SynchConsole::inputAvailable [private]
 

Definition at line 22 of file synchconsole.h.

Referenced by ReadAvail, ReadLine, SynchConsole, and ~SynchConsole.

Lock* SynchConsole::inputMutex [private]
 

Definition at line 20 of file synchconsole.h.

Referenced by ReadLine, SynchConsole, and ~SynchConsole.

Semaphore* SynchConsole::outputDone [private]
 

Definition at line 23 of file synchconsole.h.

Referenced by SynchConsole, WriteDone, WriteLine, and ~SynchConsole.

Lock* SynchConsole::outputMutex [private]
 

Definition at line 21 of file synchconsole.h.

Referenced by SynchConsole, WriteLine, and ~SynchConsole.


The documentation for this class was generated from the following files:
Generated on Mon Feb 10 09:54:58 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees