home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume44
/
toy_os
/
part04
/
processes.h
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-05
|
2KB
|
67 lines
// This may look like C code, but it is really -*- C++ -*-
/*
************************************************************************
*
* UNT Virtual Machine
*
* Process handling and scheduling
*
************************************************************************
*/
#ifndef _processes_h
#define _processes_h 1
#pragma interface
#include "hardware.h"
#include "sysqueues.h"
#include "mem_manager.h"
typedef unsigned short PID; // Process ID
const PID NIL_pid = 0; // Other PIDs are positive
// Process Control Block
class PCB : public Context, public QueueLink, public MMContext
{
public:
enum PCB_STATUS { Ok, Wait_for_kids, Wait_on_sema, Dead, Doing_io,
Shall_die } status;
PID parent; // Parent process ID (may be NIL_pid)
PID lchild; // Left child ID
PID rchild; // Right child ID
PCB(void);
~PCB(void) {}
void dump(void); // Print all the info about this
// PCB
void fork_from_dad(PCB& dad); // Fork this PCB from dad's
void brand_new(void); // PCB for a brand-new process
void save_context(const CentralProcessingUnit& cpu_hardware);
void load_context(CentralProcessingUnit& cpu_hardware);
};
class ProcessTable : public DiagnosticPanel
{
PCB * pcbs; // Array of PCB
const int nslots; // No. of slots (max value for Index)
BasicQueue freePCBs; // Queue of free PCB's
PID resume_scan_pid; // PID for scanning a blocked process
public:
ProcessTable(const int nslots);
~ProcessTable(void) {}
PCB& operator [] (const PID pid); // Get a PCB by its id
void dump(void); // Dump info on processes in system
PID new_pid(void); // Get PID of a process to create
void dispose(const PID pid); // Dispose of the PCB
void start_scan(void) { resume_scan_pid = 1; }
enum SEARCH_CRIT { Blocked, Ready };
PID next_pcb(const SEARCH_CRIT crit); // Find next pcb according to some crit
int q_all_free(void) { return freePCBs.q_no_elems() == nslots; }
};
#endif