home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume44 / toy_os / part04 / processes.h < prev    next >
C/C++ Source or Header  |  1994-09-05  |  2KB  |  67 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /*
  3.  ************************************************************************
  4.  *
  5.  *               UNT Virtual Machine
  6.  *
  7.  *               Process handling and scheduling
  8.  *
  9.  ************************************************************************
  10.  */
  11.  
  12. #ifndef _processes_h
  13. #define _processes_h 1
  14. #pragma interface
  15.  
  16. #include "hardware.h"
  17. #include "sysqueues.h"
  18. #include "mem_manager.h"
  19.  
  20. typedef unsigned short PID;        // Process ID
  21. const PID NIL_pid = 0;            // Other PIDs are positive
  22.  
  23.                 // Process Control Block
  24. class PCB : public Context, public QueueLink, public MMContext
  25. {
  26. public:
  27.   enum PCB_STATUS { Ok, Wait_for_kids, Wait_on_sema, Dead, Doing_io, 
  28.             Shall_die } status;
  29.  
  30.   PID parent;                // Parent process ID (may be NIL_pid)
  31.   PID lchild;                // Left child ID
  32.   PID rchild;                // Right child ID
  33.   
  34.   PCB(void);
  35.   ~PCB(void) {}
  36.   void dump(void);            // Print all the info about this
  37.                     // PCB
  38.   void fork_from_dad(PCB& dad);        // Fork this PCB from dad's
  39.   void brand_new(void);            // PCB for a brand-new process
  40.   void save_context(const CentralProcessingUnit& cpu_hardware);
  41.   void load_context(CentralProcessingUnit& cpu_hardware);
  42. };
  43.  
  44. class ProcessTable : public DiagnosticPanel
  45. {
  46.   PCB * pcbs;            // Array of PCB
  47.   const int nslots;        // No. of slots (max value for Index)
  48.  
  49.   BasicQueue freePCBs;        // Queue of free PCB's
  50.  
  51.   PID resume_scan_pid;        // PID for scanning a blocked process
  52.  
  53. public:
  54.   ProcessTable(const int nslots);
  55.   ~ProcessTable(void) {}
  56.   PCB& operator [] (const PID pid);    // Get a PCB by its id
  57.   void dump(void);            // Dump info on processes in system
  58.   PID new_pid(void);            // Get PID of a process to create
  59.   void dispose(const PID pid);        // Dispose of the PCB
  60.   void start_scan(void)            { resume_scan_pid = 1; }
  61.   enum SEARCH_CRIT { Blocked, Ready };
  62.   PID next_pcb(const SEARCH_CRIT crit);    // Find next pcb according to some crit
  63.   int q_all_free(void)        { return freePCBs.q_no_elems() == nslots; }
  64. };
  65.  
  66. #endif
  67.