home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume44
/
toy_os
/
part04
/
io_requests.cc
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-05
|
3KB
|
125 lines
// This may look like C code, but it is really -*- C++ -*-
/*
************************************************************************
*
* UNT Virtual Machine
*
* Managing input/output requests
* by which the CPU and I/O managers communicate with each other
*
************************************************************************
*/
#include "io_manager.h"
#include "myenv.h"
/*
*------------------------------------------------------------------------
* Elementary operations on the contents of a
* single request
*/
IORequest::IORequest(void)
{
pid = NIL_pid;
device_no = 0;
buffer_ptr = return_code_vptr = return_code_pptr = 0;
rec_count = disk_address = 0;
return_code = 0;
register int i;
for(i=0; i<max_no_recs; i++)
io_pages[i] = 0;
}
void IORequest::dump(void) const
{
message("\nI/O request block #%d for %s operation of process #%d"
"\n\ton device #%d, to record buffer %o, record count %d, "
"from sector %d."
"\n\tReturn code is to be written at %o. Return code so far is %d\n",
id, (operation == IO_READ ? "read" : "write"), pid,
device_no,buffer_ptr,rec_count,disk_address,return_code_vptr,
return_code);
}
// Dispose of the request block
void IORequest::dispose(void)
{
pid = NIL_pid;
device_no = 0;
buffer_ptr = return_code_vptr = return_code_pptr = 0;
rec_count = disk_address = 0;
return_code = 0;
assert( io_pages[0] == 0 ); // Just to make sure the pages were
// unlocked
}
/*
*------------------------------------------------------------------------
* Constructing the request table
*/
IORequestTable::IORequestTable(const int no_slots)
: nslots(no_slots)
{
assure(nslots > 4,"Number of I/O request slots must be at least 5");
reqs = new IORequest[nslots];
register RID i;
for(i=1; i<=nslots; i++)
{
IORequest& req = (*this)[i];
req.id = i;
req.key = 0;
freeIORs.append(req);
}
}
/*
*------------------------------------------------------------------------
* Elementary request table operations
*/
// Get a request given its no
IORequest& IORequestTable::operator [] (const RID rid) const
{
if( rid == NIL_rid )
_error("FATAL: Requested IORequest id is NIL");
if( rid > nslots )
_error("FATAL: IORequest id %d is too big",rid);
return reqs[rid-1];
}
// Print info about requests
void IORequestTable::dump(void) const
{
register int i;
for(i=1; i<=nslots; i++)
{
IORequest& req = (*this)[i];
if( req.pid != NIL_pid )
req.dump();
}
}
// Allocate a new request, return NIL
// if the system run out of templates
RID IORequestTable::new_request(void)
{
if( freeIORs.is_empty() )
return NIL_rid;
return freeIORs.get_from_head()->id;
}
// Dispose of the given IORequest
void IORequestTable::dispose(const RID rid)
{
IORequest& req = (*this)[rid];
assert( rid == req.id );
req.dispose();
freeIORs.append(req);
}