Modified timer function and such to stop the warnings.
This commit is contained in:
parent
5d8edb8271
commit
022ca3ac06
5 changed files with 55 additions and 13 deletions
BIN
Sim03/sim03
BIN
Sim03/sim03
Binary file not shown.
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
// void *simThread(int milSec)
|
||||
// {
|
||||
// runTimer(milSec);
|
||||
// pthread_exit(NULL);
|
||||
// }
|
||||
|
|
@ -229,6 +229,6 @@ Device Input/Device: none
|
|||
Device Output/Device: none
|
||||
Dependencies: ???
|
||||
*/
|
||||
void *simThread(int milSec);
|
||||
// void *simThread(int milSec);
|
||||
|
||||
#endif // SIMULATORX
|
||||
Loading…
Add table
Add a link
Reference in a new issue