00001 // synchdisk.h 00002 // Data structures to export a synchronous interface to the raw 00003 // disk device. 00004 // 00005 // Copyright (c) 1992-1993 The Regents of the University of California. 00006 // All rights reserved. See copyright.h for copyright notice and limitation 00007 // of liability and disclaimer of warranty provisions. 00008 00009 #include "copyright.h" 00010 00011 #ifndef SYNCHDISK_H 00012 #define SYNCHDISK_H 00013 00014 #include "disk.h" 00015 #include "synch.h" 00016 00017 // The following class defines a "synchronous" disk abstraction. 00018 // As with other I/O devices, the raw physical disk is an asynchronous device -- 00019 // requests to read or write portions of the disk return immediately, 00020 // and an interrupt occurs later to signal that the operation completed. 00021 // (Also, the physical characteristics of the disk device assume that 00022 // only one operation can be requested at a time). 00023 // 00024 // This class provides the abstraction that for any individual thread 00025 // making a request, it waits around until the operation finishes before 00026 // returning. 00027 class SynchDisk { 00028 public: 00029 SynchDisk(char* name); // Initialize a synchronous disk, 00030 // by initializing the raw Disk. 00031 ~SynchDisk(); // De-allocate the synch disk data 00032 00033 void ReadSector(int sectorNumber, char* data); 00034 // Read/write a disk sector, returning 00035 // only once the data is actually read 00036 // or written. These call 00037 // Disk::ReadRequest/WriteRequest and 00038 // then wait until the request is done. 00039 void WriteSector(int sectorNumber, char* data); 00040 00041 void RequestDone(); // Called by the disk device interrupt 00042 // handler, to signal that the 00043 // current disk operation is complete. 00044 00045 private: 00046 Disk *disk; // Raw disk device 00047 Semaphore *semaphore; // To synchronize requesting thread 00048 // with the interrupt handler 00049 Lock *lock; // Only one read/write request 00050 // can be sent to the disk at a time 00051 }; 00052 00053 #endif // SYNCHDISK_H
1.2.14 written by Dimitri van Heesch,
© 1997-2002