Expanding out ideas on Simulator 2... trying to get everything working
This commit is contained in:
parent
93904cb2f3
commit
62418ec35a
5 changed files with 138 additions and 12 deletions
|
|
@ -1,6 +1,72 @@
|
|||
#include "configops.h"
|
||||
#include "metadataops.h"
|
||||
#include "StandardConstants.h"
|
||||
#include "simulator.h"
|
||||
|
||||
/*
|
||||
Name: createProcessList
|
||||
Process: reads through the opcode struct to fill out the linked list of PCBs
|
||||
Function Input/Parameters: metadata (OpCodeType *)
|
||||
Function Output/Parameters: none
|
||||
Function Output/Returned: head pointer to the PCBs
|
||||
Device Input/Device: none
|
||||
Device Output/Device: none
|
||||
Dependencies: malloc, sizeof, ???
|
||||
*/
|
||||
ProcessControlBlockLL *createProcessList(OpCodeType *metadataPtr)
|
||||
{
|
||||
// allocate and create the ProcessControlBlockLL using malloc and size of
|
||||
ProcessControlBlockLL *headBlock;
|
||||
headBlock = malloc(sizeof(ProcessControlBlockLL));
|
||||
// set the head pointer to NULL
|
||||
headBlock->headPtr = NULL;
|
||||
// return headBlock
|
||||
return headBlock;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: destroyProcessList
|
||||
Process: deallocates memory used for the linked list struct
|
||||
Function Input/Parameters: head pointer to linked list (ProcessControlBlockLL *)
|
||||
Function Output/Parameters: none
|
||||
Function Output/Returned: NULL
|
||||
Device Input/Device: none
|
||||
Device Output/Device: none
|
||||
Dependencies: free, destroyProcessListHelper, ???
|
||||
*/
|
||||
ProcessControlBlockLL *destroyProcessList(ProcessControlBlockLL *linkedListPtr)
|
||||
{
|
||||
// call the first destroyProcessListHelper
|
||||
destroyProcessListHelper(linkedListPtr->headPtr);
|
||||
// free the rest of the struct
|
||||
free(linkedListPtr);
|
||||
// return null
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: destroyProcessListHelper
|
||||
Process: recursively clears the PCB linked list struct, freeing the struct
|
||||
Function Input/Parameters: head pointer to linked list (ProcessControlBlockLL *)
|
||||
Function Output/Parameters: none
|
||||
Function Output/Returned: NULL
|
||||
Device Input/Device: none
|
||||
Device Output/Device: none
|
||||
Dependencies: free, destroyProcessListHelper(recursively), ???
|
||||
*/
|
||||
ProcessControlBlock *destroyProcessListHelper(ProcessControlBlock *nodePtr)
|
||||
{
|
||||
// check to see if the next pointer is NOT null
|
||||
if(nodePtr->nextPtr != NULL)
|
||||
{
|
||||
// if not null, move to the next pointer (recurse)
|
||||
nodePtr->nextPtr = destroyProcessListHelper(nodePtr->nextPtr);
|
||||
}
|
||||
// free the 'parent' node
|
||||
free(nodePtr);
|
||||
// return null
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: runSim
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue