diff --git a/Sim03/sim03 b/Sim03/sim03 index 393e6ba..047dfc9 100755 Binary files a/Sim03/sim03 and b/Sim03/sim03 differ diff --git a/Sim03/simtimer.c b/Sim03/simtimer.c index c3fbd23..0c1bdfe 100644 --- a/Sim03/simtimer.c +++ b/Sim03/simtimer.c @@ -30,11 +30,13 @@ const char RADIX_POINT = '.'; const char SPACED = ' '; -void runTimer( int milliSeconds ) +void *runTimer( void *mSecVoidPtr ) { struct timeval startTime, endTime; int startSec, startUSec, endSec, endUSec; int uSecDiff, mSecDiff, secDiff, timeDiff; + int *mSecPtr = (int *)mSecVoidPtr; + int milliSeconds = *mSecPtr; gettimeofday( &startTime, NULL ); @@ -62,9 +64,44 @@ void runTimer( int milliSeconds ) secDiff = ( endSec - startSec ) * 1000; timeDiff = secDiff + mSecDiff; } - // return NULL; + return NULL; } + // void runTimer(int milliSeconds) + // { + // struct timeval startTime, endTime; + // int startSec, startUSec, endSec, endUSec; + // int uSecDiff, mSecDiff, secDiff, timeDiff; + + // gettimeofday(&startTime, NULL); + + // startSec = startTime.tv_sec; + // startUSec = startTime.tv_usec; + + // timeDiff = 0; + + // while (timeDiff < milliSeconds) + // { + // gettimeofday(&endTime, NULL); + + // endSec = endTime.tv_sec; + // endUSec = endTime.tv_usec; + // uSecDiff = endUSec - startUSec; + + // if (uSecDiff < 0) + // { + // uSecDiff = uSecDiff + 1000000; + + // endSec = endSec - 1; + // } + + // mSecDiff = uSecDiff / 1000; + // secDiff = (endSec - startSec) * 1000; + // timeDiff = secDiff + mSecDiff; + // } + // // return NULL; + // } + double accessTimer( int controlCode, char *timeStr ) { static bool running = false; diff --git a/Sim03/simtimer.h b/Sim03/simtimer.h index fe0496a..f57ae94 100644 --- a/Sim03/simtimer.h +++ b/Sim03/simtimer.h @@ -35,7 +35,7 @@ extern const char SPACED; // Function Prototyp ///////////////////////////////////////////////////////// -void runTimer( int milliSeconds ); +void *runTimer(void *mSecVoidPtr); // 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 diff --git a/Sim03/simulator.c b/Sim03/simulator.c index 5699961..5aeda88 100644 --- a/Sim03/simulator.c +++ b/Sim03/simulator.c @@ -599,12 +599,13 @@ void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr // int intArg = workingMeta->intArg2; char cpuOutput[MAX_STR_LEN]; int cpuTime = 0; + int *cpuTimePtr = &cpuTime; cpuTime = intArg * configPtr->procCycleRate; sprintf(cpuOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument); logOutput(configPtr, cpuOutput, false); // run timer for intArg * procCycleRate pthread_t cpuThread; - pthread_create(&cpuThread, NULL, (void *)&simThread, (void *)cpuTime); + pthread_create(&cpuThread, NULL, runTimer, (void *)cpuTimePtr); pthread_join(cpuThread, NULL); sprintf(cpuOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument); logOutput(configPtr, cpuOutput, false); @@ -626,11 +627,12 @@ void runIO(char *command, char *argument, int intArg, ConfigDataType *configPtr, char timeStringy[MAX_STR_LEN]; char ioOutput[MAX_STR_LEN]; int ioTime = 0; + int *ioTimePtr = &ioTime; ioTime = intArg * configPtr->ioCycleRate; sprintf(ioOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument); logOutput(configPtr, ioOutput, false); pthread_t ioThread; - pthread_create(&ioThread, NULL, (void *)&simThread, (void *)ioTime); + pthread_create(&ioThread, NULL, runTimer, (void *)ioTimePtr); pthread_join(ioThread, NULL); sprintf(ioOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument); logOutput(configPtr, ioOutput, false); @@ -782,13 +784,15 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) processCount = processCount + 1; } pcbPtr = pcbList->headPtr; + int *totalPCBTimePtr = &totalPCBTime; pthread_t cpuThread; - pthread_create(&cpuThread, NULL, (void *)&simThread, (void *)totalPCBTime); + pthread_create(&cpuThread, NULL, runTimer, (void *)totalPCBTimePtr); // int processTimeLeft = pcbPtr->timeLeft; + int *processTimeLeftPtr = &processTimeLeft; // set the current process id to the first scheduled process currentPid = scheduleProcess(pcbList, configPtr); @@ -811,7 +815,7 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) sprintf(simulatorOutput, "%f, OS: Process %d set to RUNNING state from READY state\n\n", accessTimer(LAP_TIMER, timeStringy), pcbPtr->uniquePid); logOutput(configPtr, simulatorOutput, false); pthread_t runThread; - pthread_create(&runThread, NULL, (void *)&simThread, (void *)processTimeLeft); + pthread_create(&runThread, NULL, runTimer, (void *)processTimeLeftPtr); runProcess(pcbPtr, configPtr, pcbList); // when finished, set to terminated sprintf(simulatorOutput, "%f, OS: Process %d set to TERMINATED state from RUNNING state\n\n", accessTimer(LAP_TIMER, timeStringy), pcbPtr->uniquePid); @@ -820,6 +824,7 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) pthread_join(runThread, NULL); } processTimeLeft = pcbPtr->timeLeft; + processTimeLeftPtr = &processTimeLeft; pcbPtr = pcbPtr->nextPtr; } currentPid = scheduleProcess(pcbList, configPtr); @@ -1007,8 +1012,8 @@ Device Input/Device: none Device Output/Device: none Dependencies: pthreads, runTimer */ -void *simThread(int milSec) -{ - runTimer(milSec); - pthread_exit(NULL); -} \ No newline at end of file +// void *simThread(int milSec) +// { +// runTimer(milSec); +// pthread_exit(NULL); +// } \ No newline at end of file diff --git a/Sim03/simulator.h b/Sim03/simulator.h index 4ce4906..9e9e59f 100644 --- a/Sim03/simulator.h +++ b/Sim03/simulator.h @@ -229,6 +229,6 @@ Device Input/Device: none Device Output/Device: none Dependencies: ??? */ -void *simThread(int milSec); +// void *simThread(int milSec); #endif // SIMULATORX \ No newline at end of file