home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / hl10osrc.lzh / Include / vm.h < prev   
Text File  |  1994-04-23  |  4KB  |  98 lines

  1. /* -*- Mode: C -*- */
  2. /* vm.h - Virtual Memory hackery.
  3.  * Created by Robert Heller on Fri Dec  6 20:37:13 1991
  4.  *
  5.  * ------------------------------------------------------------------
  6.  * Home Libarian by Deepwoods Software
  7.  * Common Header Files
  8.  * ------------------------------------------------------------------
  9.  * Modification History:
  10.  * ------------------------------------------------------------------
  11.  * Contents:
  12.  * ------------------------------------------------------------------
  13.  * 
  14.  * 
  15.  * Copyright (c) 1991,1992 by Robert heller (D/B/A Deepwoods Software)
  16.  *        All Rights Reserved
  17.  * 
  18.  */
  19. #ifndef _VM_
  20. #define _VM_
  21. #include <common.h>
  22. #define SEEK_SET 0
  23. #define SEEK_END 2
  24.  
  25. // This class implements the base level disk I/O for pages and records.
  26. // It also does the working set management (deciding when to page in a
  27. // page and when to page out a page)
  28. class PageFile {
  29. protected:
  30.     int fd;                // the file descriptor itself
  31.     Boolean isopen;            // are we really open?
  32.     Direction direction;        // which way?
  33.     const NumPTEntries = 50;    // WSMAX.  Max number of core
  34.                     // resident pages
  35.     int numpagesincore;        // WSCURRENT.  Current number
  36.                     // of pages actually in memory.
  37.     PTEntry pagetable[NumPTEntries]; // This is our page table.
  38.     PTEntry temp;            // Scratch PT entry.
  39.     Boolean PageRead(PTEntry&);    // Read a page
  40.     Boolean PageWrite(PTEntry&);    // Write a page
  41.     PTEntry & FindPage(DiskPage);    // Find a page (might cause a page in,
  42.                     // which might in turn cause a page
  43.                     // out).
  44. public:
  45.     // Open the file.  Does base level file open.
  46.     OpenStatus open (char *filename,Direction direction,
  47.               int flags = ReadWriteFlags,
  48.               int mode = ReadWriteMode,
  49.               Boolean create_if = false);
  50.     // Close the file.  Does base level file close.  Any core-resident
  51.     // pages that are "dirty" (modified) are written to disk.
  52.     void close ();
  53.     // Constructor
  54.          PageFile ()
  55.         {
  56.             isopen = false;
  57.             numpagesincore = 0;
  58.             for (int i = 0;i<NumPTEntries;i++) {
  59.                 pagetable[i].isdirty = false;
  60.                 pagetable[i].corepage = 0;
  61.             }
  62.         }
  63.     // Destructor.  Makes sure the file is closed.  (close() is
  64.     // ok for a closed file - it is a noop then.)
  65.         ~PageFile () {close();}
  66.     // Make a new page.
  67.     DiskPage NewPage();
  68.     // Base level record I/O
  69.     int ReadRecord(DiskRecord&, char *, int);
  70.     DiskRecord WriteRecord(char *,int);
  71.     DiskRecord ReWriteRecord(DiskRecord&, char *,int);
  72.     // The [] operator does DiskPage to core Page mapping.
  73.     // Uses FindPage to find the page.  FindPage will bring the page
  74.     // into memory if needed.  Note:  A call to this operator
  75.     // could cause a page out.  ALLWAYS call [] to get an up-to-date
  76.     // pointer to a Page* before referencing the core page.  ALLWAYS
  77.     // *COPY* to local storage any pieces of a page before calling
  78.     // [] again if you plan to copy a bit of info from one page to
  79.     // another.
  80.     Page * operator [] (long addr) {DiskPage page(addr);
  81.                     return((FindPage(page).corepage));}
  82.     Page * operator [] (DiskPage page) 
  83.                     {return((FindPage(page).corepage));}
  84.     // The () operator gets a reference to the PT entry.  ALLWAYS call
  85.     // () and update the isdirty field after you modify a page and before
  86.     // calling [].  It is not a good idea to keep a local copy of the
  87.     // PT entry reference around, since they move around and a local
  88.     // copy of the PT entry is not meaningfull, since the contents
  89.     // is not stable.
  90.     PTEntry & operator () (long addr) {DiskPage page(addr);
  91.                        return(FindPage(page));}
  92.     PTEntry & operator () (DiskPage page) {return(FindPage(page));}
  93. };
  94.  
  95.  
  96. #endif
  97.  
  98.