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 RADIX_POINT = '.';
|
||||||
const char SPACED = ' ';
|
const char SPACED = ' ';
|
||||||
|
|
||||||
void runTimer( int milliSeconds )
|
void *runTimer( void *mSecVoidPtr )
|
||||||
{
|
{
|
||||||
struct timeval startTime, endTime;
|
struct timeval startTime, endTime;
|
||||||
int startSec, startUSec, endSec, endUSec;
|
int startSec, startUSec, endSec, endUSec;
|
||||||
int uSecDiff, mSecDiff, secDiff, timeDiff;
|
int uSecDiff, mSecDiff, secDiff, timeDiff;
|
||||||
|
int *mSecPtr = (int *)mSecVoidPtr;
|
||||||
|
int milliSeconds = *mSecPtr;
|
||||||
|
|
||||||
gettimeofday( &startTime, NULL );
|
gettimeofday( &startTime, NULL );
|
||||||
|
|
||||||
|
|
@ -62,9 +64,44 @@ void runTimer( int milliSeconds )
|
||||||
secDiff = ( endSec - startSec ) * 1000;
|
secDiff = ( endSec - startSec ) * 1000;
|
||||||
timeDiff = secDiff + mSecDiff;
|
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 )
|
double accessTimer( int controlCode, char *timeStr )
|
||||||
{
|
{
|
||||||
static bool running = false;
|
static bool running = false;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ extern const char SPACED;
|
||||||
|
|
||||||
// Function Prototyp /////////////////////////////////////////////////////////
|
// Function Prototyp /////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void runTimer( int milliSeconds );
|
void *runTimer(void *mSecVoidPtr);
|
||||||
// will run a timer for the amount of ms specified
|
// will run a timer for the amount of ms specified
|
||||||
double accessTimer( int controlCode, char *timeStr );
|
double accessTimer( int controlCode, char *timeStr );
|
||||||
// returns the actual time as a double AND as a time string
|
// 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;
|
// int intArg = workingMeta->intArg2;
|
||||||
char cpuOutput[MAX_STR_LEN];
|
char cpuOutput[MAX_STR_LEN];
|
||||||
int cpuTime = 0;
|
int cpuTime = 0;
|
||||||
|
int *cpuTimePtr = &cpuTime;
|
||||||
cpuTime = intArg * configPtr->procCycleRate;
|
cpuTime = intArg * configPtr->procCycleRate;
|
||||||
sprintf(cpuOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
sprintf(cpuOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
||||||
logOutput(configPtr, cpuOutput, false);
|
logOutput(configPtr, cpuOutput, false);
|
||||||
// run timer for intArg * procCycleRate
|
// run timer for intArg * procCycleRate
|
||||||
pthread_t cpuThread;
|
pthread_t cpuThread;
|
||||||
pthread_create(&cpuThread, NULL, (void *)&simThread, (void *)cpuTime);
|
pthread_create(&cpuThread, NULL, runTimer, (void *)cpuTimePtr);
|
||||||
pthread_join(cpuThread, NULL);
|
pthread_join(cpuThread, NULL);
|
||||||
sprintf(cpuOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
sprintf(cpuOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
||||||
logOutput(configPtr, cpuOutput, false);
|
logOutput(configPtr, cpuOutput, false);
|
||||||
|
|
@ -626,11 +627,12 @@ void runIO(char *command, char *argument, int intArg, ConfigDataType *configPtr,
|
||||||
char timeStringy[MAX_STR_LEN];
|
char timeStringy[MAX_STR_LEN];
|
||||||
char ioOutput[MAX_STR_LEN];
|
char ioOutput[MAX_STR_LEN];
|
||||||
int ioTime = 0;
|
int ioTime = 0;
|
||||||
|
int *ioTimePtr = &ioTime;
|
||||||
ioTime = intArg * configPtr->ioCycleRate;
|
ioTime = intArg * configPtr->ioCycleRate;
|
||||||
sprintf(ioOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
sprintf(ioOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
||||||
logOutput(configPtr, ioOutput, false);
|
logOutput(configPtr, ioOutput, false);
|
||||||
pthread_t ioThread;
|
pthread_t ioThread;
|
||||||
pthread_create(&ioThread, NULL, (void *)&simThread, (void *)ioTime);
|
pthread_create(&ioThread, NULL, runTimer, (void *)ioTimePtr);
|
||||||
pthread_join(ioThread, NULL);
|
pthread_join(ioThread, NULL);
|
||||||
sprintf(ioOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
sprintf(ioOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
||||||
logOutput(configPtr, ioOutput, false);
|
logOutput(configPtr, ioOutput, false);
|
||||||
|
|
@ -782,13 +784,15 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
||||||
processCount = processCount + 1;
|
processCount = processCount + 1;
|
||||||
}
|
}
|
||||||
pcbPtr = pcbList->headPtr;
|
pcbPtr = pcbList->headPtr;
|
||||||
|
int *totalPCBTimePtr = &totalPCBTime;
|
||||||
|
|
||||||
|
|
||||||
pthread_t cpuThread;
|
pthread_t cpuThread;
|
||||||
pthread_create(&cpuThread, NULL, (void *)&simThread, (void *)totalPCBTime);
|
pthread_create(&cpuThread, NULL, runTimer, (void *)totalPCBTimePtr);
|
||||||
|
|
||||||
//
|
//
|
||||||
int processTimeLeft = pcbPtr->timeLeft;
|
int processTimeLeft = pcbPtr->timeLeft;
|
||||||
|
int *processTimeLeftPtr = &processTimeLeft;
|
||||||
|
|
||||||
// set the current process id to the first scheduled process
|
// set the current process id to the first scheduled process
|
||||||
currentPid = scheduleProcess(pcbList, configPtr);
|
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);
|
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);
|
logOutput(configPtr, simulatorOutput, false);
|
||||||
pthread_t runThread;
|
pthread_t runThread;
|
||||||
pthread_create(&runThread, NULL, (void *)&simThread, (void *)processTimeLeft);
|
pthread_create(&runThread, NULL, runTimer, (void *)processTimeLeftPtr);
|
||||||
runProcess(pcbPtr, configPtr, pcbList);
|
runProcess(pcbPtr, configPtr, pcbList);
|
||||||
// when finished, set to terminated
|
// 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);
|
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);
|
pthread_join(runThread, NULL);
|
||||||
}
|
}
|
||||||
processTimeLeft = pcbPtr->timeLeft;
|
processTimeLeft = pcbPtr->timeLeft;
|
||||||
|
processTimeLeftPtr = &processTimeLeft;
|
||||||
pcbPtr = pcbPtr->nextPtr;
|
pcbPtr = pcbPtr->nextPtr;
|
||||||
}
|
}
|
||||||
currentPid = scheduleProcess(pcbList, configPtr);
|
currentPid = scheduleProcess(pcbList, configPtr);
|
||||||
|
|
@ -1007,8 +1012,8 @@ Device Input/Device: none
|
||||||
Device Output/Device: none
|
Device Output/Device: none
|
||||||
Dependencies: pthreads, runTimer
|
Dependencies: pthreads, runTimer
|
||||||
*/
|
*/
|
||||||
void *simThread(int milSec)
|
// void *simThread(int milSec)
|
||||||
{
|
// {
|
||||||
runTimer(milSec);
|
// runTimer(milSec);
|
||||||
pthread_exit(NULL);
|
// pthread_exit(NULL);
|
||||||
}
|
// }
|
||||||
|
|
@ -229,6 +229,6 @@ Device Input/Device: none
|
||||||
Device Output/Device: none
|
Device Output/Device: none
|
||||||
Dependencies: ???
|
Dependencies: ???
|
||||||
*/
|
*/
|
||||||
void *simThread(int milSec);
|
// void *simThread(int milSec);
|
||||||
|
|
||||||
#endif // SIMULATORX
|
#endif // SIMULATORX
|
||||||
Loading…
Add table
Add a link
Reference in a new issue