diff --git a/Sim02/sim02_mf b/Sim02/sim02_mf index 9735d6c..512f7a4 100644 --- a/Sim02/sim02_mf +++ b/Sim02/sim02_mf @@ -1,6 +1,6 @@ CC = gcc -Wall -std=c99 -pedantic -g -SOURCES = StringUtils.c simulator.c metadataops.c configops.c OS_SimDriver.c -OBJECTS = OS_SimDriver.o simulator.o metadataops.o configops.o StringUtils.o +SOURCES = StringUtils.c simulator.c metadataops.c configops.c OS_SimDriver.c simtimer.c +OBJECTS = OS_SimDriver.o simulator.o metadataops.o configops.o StringUtils.o simtimer.o all: Simulator @@ -22,6 +22,9 @@ configops.o: configops.c OS_SimDriver.o: OS_SimDriver.c $(CC) -c OS_SimDriver.c -o OS_SimDriver.o +simtimer.o: simtimer.c + $(CC) -c simtimer.c -o simtimer.o + clean: rm -f $(OBJECTS) sim02 sim02.out diff --git a/Sim02/simtimer.c b/Sim02/simtimer.c index 374b580..8e04e54 100644 --- a/Sim02/simtimer.c +++ b/Sim02/simtimer.c @@ -28,8 +28,9 @@ // Constants ///////////////////////////////////////////////////////////////// const char RADIX_POINT = '.'; +const char SPACED = ' '; -void runTimer( int milliSeconds ) +void *runTimer( int milliSeconds ) { struct timeval startTime, endTime; int startSec, startUSec, endSec, endUSec; @@ -61,11 +62,12 @@ void runTimer( int milliSeconds ) secDiff = ( endSec - startSec ) * 1000; timeDiff = secDiff + mSecDiff; } + return NULL; } double accessTimer( int controlCode, char *timeStr ) { - static Boolean running = False; + static bool running = false; static int startSec = 0, endSec = 0, startUSec = 0, endUSec = 0; static int lapSec = 0, lapUSec = 0; struct timeval startData, lapData, endData; @@ -75,7 +77,7 @@ double accessTimer( int controlCode, char *timeStr ) { case ZERO_TIMER: gettimeofday( &startData, NULL ); - running = True; + running = true; startSec = startData.tv_sec; startUSec = startData.tv_usec; @@ -88,7 +90,7 @@ double accessTimer( int controlCode, char *timeStr ) break; case LAP_TIMER: - if( running == True ) + if( running == true ) { gettimeofday( &lapData, NULL ); @@ -106,10 +108,10 @@ double accessTimer( int controlCode, char *timeStr ) break; case STOP_TIMER: - if( running == True ) + if( running == true ) { gettimeofday( &endData, NULL ); - running = False; + running = false; endSec = endData.tv_sec; endUSec = endData.tv_usec; diff --git a/Sim02/simtimer.h b/Sim02/simtimer.h index 8c1969b..4539c3b 100644 --- a/Sim02/simtimer.h +++ b/Sim02/simtimer.h @@ -31,12 +31,16 @@ enum TIMER_CTRL_CODES { ZERO_TIMER, LAP_TIMER, STOP_TIMER }; extern const char RADIX_POINT; -extern const char SPACE; +extern const char SPACED; // Function Prototyp ///////////////////////////////////////////////////////// -void runTimer( int milliSeconds ); +void *runTimer( int milliSeconds ); +// will run a timer for the amount of ms specified double accessTimer( int controlCode, char *timeStr ); +// returns the actual time as a double AND as a time string + +// no more access needed beyond this point (supporting functions) double processTime( double startSec, double endSec, double startUSec, double endUSec, char *timeStr ); void timeToString( int secTime, int uSecTime, char *timeStr ); diff --git a/Sim02/simulator.c b/Sim02/simulator.c index fea9eee..036d5cc 100644 --- a/Sim02/simulator.c +++ b/Sim02/simulator.c @@ -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 diff --git a/Sim02/simulator.h b/Sim02/simulator.h index e4ab7be..9a9a0a4 100644 --- a/Sim02/simulator.h +++ b/Sim02/simulator.h @@ -24,15 +24,28 @@ typedef struct ProcessControlBlockStruct // this will be a mini loop within the master loop that goes until it // hits the app end command. // it may hold the next opcode, since you don't need to traverse backward + char *nextOpCode; // have an IO cycle count here + int ioCycles; // have a CPU cycle count here + int cpuCycles; // maybe have a total cycle count here + int totalCycles; // time left could be calculated from these. // potentially could change the cycles or have a 'left' variable to // see how many are left. // also need a time left state here? + double timeLeft; + // connect to the next process control block here + struct ProcessControlBlockStruct *nextPtr; } ProcessControlBlock; +typedef struct ProcessControlBlockLLStruct +{ + // holds the head ptr for PCBs + ProcessControlBlock *headPtr; +} ProcessControlBlockLL; + /* Name: ??? Process: ??? @@ -51,7 +64,7 @@ Dependencies: ??? /* Name: ??? Process: ??? -// Function Input/Parameters: ??? +Function Input/Parameters: ??? Function Output/Parameters: none Function Output/Returned: none Device Input/Device: none @@ -71,7 +84,45 @@ Dependencies: ??? // need a function called destroyProcessList // deallocated the ll of PCBs recursively, frees the rest of the struct. -// +// have a function to change the state of the process? +// have it take in the process struct, switch it's state and report that it +// has switched FROM a state TO a different state. + +/* +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); + +/* +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); + +/* +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); /* Name: runSim