Refuse to work on this anymore right now.
This commit is contained in:
parent
e3441e9fbd
commit
fda57566d8
26 changed files with 4988 additions and 94 deletions
|
|
@ -17,6 +17,32 @@ bool accessMemory(ProcessControlBlock *singlePCB, int offset, int size)
|
|||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: addLog
|
||||
Process: allocates the memory for the log, ...
|
||||
Function Input/Parameters: source log (logFile)
|
||||
Function Output/Parameters: none
|
||||
Function Output/Returned: filled PCB (logFile *)
|
||||
Device Input/Device: none
|
||||
Device Output/Device: none
|
||||
Dependencies: malloc, sizeof, ???
|
||||
*/
|
||||
logFile *addLog(const logFile source)
|
||||
{
|
||||
// declare a pointer to working node
|
||||
logFile *workingNode;
|
||||
// make some space that the pointer is pointing to
|
||||
workingNode = malloc(sizeof(logFile));
|
||||
// make some space for the string data
|
||||
// workingNode->stringData = malloc(sizeof(source.stringData));
|
||||
// get each value from the source, and set their values
|
||||
copyString(workingNode->stringData, source.stringData);
|
||||
// make sure to set the next pointer to NULL!
|
||||
workingNode->nextPtr = NULL;
|
||||
// return workingNode
|
||||
return workingNode;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: addProcess
|
||||
Process: allocates the memory for the pcb, grabs the data from the created PCB,
|
||||
|
|
@ -71,12 +97,33 @@ bool allocMemory(ProcessControlBlock *singlePCB, int offset, int size, int array
|
|||
singlePCB->allocatedMemOffsets[allocateIterator] = offset;
|
||||
singlePCB->allocatedMemSizes[allocateIterator] = size;
|
||||
allocateIterator = allocateIterator + 1;
|
||||
printf("Alloc Iter: %d\n", allocateIterator);
|
||||
// printf("Alloc Iter: %d\n", allocateIterator);
|
||||
}
|
||||
// return true (temp)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: createFileLogList
|
||||
Process: initializes the logging file struct
|
||||
Function Input/Parameters: none
|
||||
Function Output/Parameters: none
|
||||
Function Output/Returned: head pointer to the logfile struct
|
||||
Device Input/Device: none
|
||||
Device Output/Device: none
|
||||
Dependencies: malloc, sizeof, ???
|
||||
*/
|
||||
logFileLL *createFileLogList()
|
||||
{
|
||||
// allocate and create the logFileLL using malloc and size of
|
||||
logFileLL *headBlock;
|
||||
headBlock = malloc(sizeof(logFileLL));
|
||||
// set the head pointer to NULL
|
||||
headBlock->headPtr = NULL;
|
||||
// return headBlock
|
||||
return headBlock;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: createProcessList
|
||||
Process: reads through the opcode struct to fill out the linked list of PCBs
|
||||
|
|
@ -122,6 +169,26 @@ bool deallocMemory(ProcessControlBlock *singlePCB, int arraySize)
|
|||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: destroyFileLogList
|
||||
Process: deallocates memory used for the linked list struct
|
||||
Function Input/Parameters: head pointer to linked list (logFileLL *)
|
||||
Function Output/Parameters: none
|
||||
Function Output/Returned: NULL
|
||||
Device Input/Device: none
|
||||
Device Output/Device: none
|
||||
Dependencies: free, destroyFileLogHelper, ???
|
||||
*/
|
||||
logFileLL *destroyFileLogList(logFileLL *linkedListPtr)
|
||||
{
|
||||
// call the first destroyFileLogHelper
|
||||
destroyFileLogHelper(linkedListPtr->headPtr);
|
||||
// free the rest of the struct
|
||||
free(linkedListPtr);
|
||||
// return null
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: destroyProcessList
|
||||
Process: deallocates memory used for the linked list struct
|
||||
|
|
@ -142,6 +209,30 @@ ProcessControlBlockLL *destroyProcessList(ProcessControlBlockLL *linkedListPtr)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: destroyFileLogHelper
|
||||
Process: recursively clears the logfile linked list struct, freeing the struct
|
||||
Function Input/Parameters: head pointer to logfile list (logFile *)
|
||||
Function Output/Parameters: none
|
||||
Function Output/Returned: NULL
|
||||
Device Input/Device: none
|
||||
Device Output/Device: none
|
||||
Dependencies: free, destroyFileLogHelper(recursively), ???
|
||||
*/
|
||||
logFile *destroyFileLogHelper(logFile *nodePtr)
|
||||
{
|
||||
// check to see if the pointer is NOT null
|
||||
if (nodePtr != NULL)
|
||||
{
|
||||
// if not null, move to the next pointer (recurse)
|
||||
nodePtr->nextPtr = destroyFileLogHelper(nodePtr->nextPtr);
|
||||
}
|
||||
// free the 'parent' node
|
||||
free(nodePtr);
|
||||
// return null
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: destroyProcessListHelper
|
||||
Process: recursively clears the PCB linked list struct, freeing the struct
|
||||
|
|
@ -343,48 +434,156 @@ Device Input/Device: none
|
|||
Device Output/Device: none
|
||||
Dependencies: fprintf, ???
|
||||
*/
|
||||
void logOutput(ConfigDataType *configPtr, char *logStr, bool isEnd)
|
||||
logFileLL *logOutput(ConfigDataType *configPtr, char *logStr, bool isEnd, logFileLL *logPtr)
|
||||
{
|
||||
if(configPtr->logToCode == LOGTO_BOTH_CODE)
|
||||
logFile toLog;
|
||||
// toLog.stringData = malloc(sizeof(*logStr));
|
||||
logFile *wkgLogPtr;
|
||||
wkgLogPtr = logPtr->headPtr;
|
||||
if (configPtr->logToCode == LOGTO_BOTH_CODE)
|
||||
{
|
||||
//
|
||||
FILE *fileWritePtr;
|
||||
fileWritePtr = fopen(configPtr->logToFileName, "w+");
|
||||
if (fileWritePtr != NULL)
|
||||
// close the file, if at the end.
|
||||
if (isEnd)
|
||||
{
|
||||
fprintf(fileWritePtr, "%s", logStr);
|
||||
FILE *fileWritePtr;
|
||||
fileWritePtr = fopen(configPtr->logToFileName, "w");
|
||||
if (fileWritePtr != NULL)
|
||||
{
|
||||
//
|
||||
while(wkgLogPtr != NULL)
|
||||
{
|
||||
//
|
||||
printf("Data being written.");
|
||||
fprintf(fileWritePtr, "%s", wkgLogPtr->stringData);
|
||||
wkgLogPtr = wkgLogPtr->nextPtr;
|
||||
}
|
||||
}
|
||||
fclose(fileWritePtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
// need to add the string to the end of the LL.
|
||||
// fprintf(fileWritePtr, "%s", logStr);
|
||||
copyString(toLog.stringData, logStr);
|
||||
toLog.nextPtr = NULL;
|
||||
while(wkgLogPtr != NULL) //wkgLogPtr->nextPtr != NULL
|
||||
{
|
||||
// need to add at the end of the LL.
|
||||
// if (logPtr->headPtr == NULL)
|
||||
// {
|
||||
// printf("Added to log.");
|
||||
// logPtr->headPtr = addLog(toLog);
|
||||
// // wkgLogPtr = logPtr->headPtr;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// while(wkgLogPtr != NULL)
|
||||
// {
|
||||
// printf("Added to log at end.");
|
||||
// wkgLogPtr->nextPtr = addLog(toLog);
|
||||
// wkgLogPtr = addLog(toLog);
|
||||
// wkgLogPtr = wkgLogPtr->nextPtr;
|
||||
//
|
||||
// }
|
||||
// }
|
||||
wkgLogPtr = wkgLogPtr->nextPtr;
|
||||
}
|
||||
// if (wkgLogPtr == NULL)
|
||||
// {
|
||||
// //
|
||||
// printf("Added to end of log.");
|
||||
// wkgLogPtr = addLog(toLog);
|
||||
// }
|
||||
if (logPtr->headPtr == NULL)
|
||||
{
|
||||
printf("Added to log.");
|
||||
logPtr->headPtr = addLog(toLog);
|
||||
// wkgLogPtr = logPtr->headPtr;
|
||||
}
|
||||
// wkgLogPtr->nextPtr = addLog(toLog);
|
||||
fprintf(stdout, "%s", logStr);
|
||||
}
|
||||
// no return, void
|
||||
// close the file, if at the end.
|
||||
if (isEnd)
|
||||
{
|
||||
fclose(fileWritePtr);
|
||||
}
|
||||
// fclose(fileWritePtr);
|
||||
}
|
||||
else if(configPtr->logToCode == LOGTO_FILE_CODE)
|
||||
else if (configPtr->logToCode == LOGTO_FILE_CODE)
|
||||
{
|
||||
//
|
||||
printf("\nSimulator will output to a file.\n");
|
||||
FILE *fileWritePtr;
|
||||
fileWritePtr = fopen(configPtr->logToFileName, "w+");
|
||||
if (fileWritePtr != NULL)
|
||||
{
|
||||
fprintf(fileWritePtr, "%s", logStr);
|
||||
}
|
||||
// no return, void
|
||||
// close the file, if at the end.
|
||||
if (isEnd)
|
||||
{
|
||||
fclose(fileWritePtr);
|
||||
}
|
||||
// fclose(fileWritePtr);
|
||||
// if (isEnd)
|
||||
// {
|
||||
// printf("\nSimulator will output to a file.\n");
|
||||
// FILE *fileWritePtr;
|
||||
// fileWritePtr = fopen(configPtr->logToFileName, "w");
|
||||
// if (fileWritePtr != NULL)
|
||||
// {
|
||||
// //
|
||||
// while(wkgLogPtr->nextPtr != NULL)
|
||||
// {
|
||||
// //
|
||||
// fprintf(fileWritePtr, "%s", wkgLogPtr->stringData);
|
||||
// wkgLogPtr = wkgLogPtr->nextPtr;
|
||||
// }
|
||||
// }
|
||||
// fclose(fileWritePtr);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // need to add the string to the end of the LL.
|
||||
// // fprintf(fileWritePtr, "%s", logStr);
|
||||
// copyString(toLog.stringData, logStr);
|
||||
// toLog.nextPtr = NULL;
|
||||
// while(wkgLogPtr->nextPtr != NULL)
|
||||
// {
|
||||
// //
|
||||
// wkgLogPtr = wkgLogPtr->nextPtr;
|
||||
// }
|
||||
// wkgLogPtr->nextPtr = addLog(toLog);
|
||||
// // fprintf(stdout, "%s", logStr);
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stdout, "%s", logStr);
|
||||
}
|
||||
// if(configPtr->logToCode == LOGTO_BOTH_CODE)
|
||||
// {
|
||||
// //
|
||||
// FILE *fileWritePtr;
|
||||
// fileWritePtr = fopen(configPtr->logToFileName, "w+");
|
||||
// if (fileWritePtr != NULL)
|
||||
// {
|
||||
// fprintf(fileWritePtr, "%s", logStr);
|
||||
// fprintf(stdout, "%s", logStr);
|
||||
// }
|
||||
// // no return, void
|
||||
// // close the file, if at the end.
|
||||
// if (isEnd)
|
||||
// {
|
||||
// fclose(fileWritePtr);
|
||||
// }
|
||||
// // fclose(fileWritePtr);
|
||||
// }
|
||||
// else if(configPtr->logToCode == LOGTO_FILE_CODE)
|
||||
// {
|
||||
// //
|
||||
// printf("\nSimulator will output to a file.\n");
|
||||
// FILE *fileWritePtr;
|
||||
// fileWritePtr = fopen(configPtr->logToFileName, "w+");
|
||||
// if (fileWritePtr != NULL)
|
||||
// {
|
||||
// fprintf(fileWritePtr, "%s", logStr);
|
||||
// }
|
||||
// // no return, void
|
||||
// // close the file, if at the end.
|
||||
// if (isEnd)
|
||||
// {
|
||||
// fclose(fileWritePtr);
|
||||
// }
|
||||
// // fclose(fileWritePtr);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// fprintf(stdout, "%s", logStr);
|
||||
// }
|
||||
return logPtr;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -400,7 +599,7 @@ Device Input/Device: none
|
|||
Device Output/Device: none
|
||||
Dependencies: ???
|
||||
*/
|
||||
bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offset, int size, ConfigDataType *configPtr, ProcessControlBlock *singlePCB)
|
||||
bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offset, int size, ConfigDataType *configPtr, ProcessControlBlock *singlePCB, logFileLL *logList)
|
||||
{
|
||||
bool memDisplay = configPtr->memDisplay;
|
||||
ProcessControlBlock *wkgPtr;
|
||||
|
|
@ -591,7 +790,7 @@ Device Input/Device: none
|
|||
Device Output/Device: none
|
||||
Dependencies: pthreads, sprintf, logOutput, ???
|
||||
*/
|
||||
void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId)
|
||||
void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId, logFileLL *logList)
|
||||
{
|
||||
char timeStringy[MAX_STR_LEN];
|
||||
// char *command = workingMeta->command;
|
||||
|
|
@ -602,13 +801,13 @@ void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr
|
|||
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);
|
||||
logOutput(configPtr, cpuOutput, false, logList);
|
||||
// run timer for intArg * procCycleRate
|
||||
pthread_t cpuThread;
|
||||
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);
|
||||
logOutput(configPtr, cpuOutput, false, logList);
|
||||
// pthread_exit(NULL);
|
||||
}
|
||||
|
||||
|
|
@ -622,7 +821,7 @@ Device Input/Device: none
|
|||
Device Output/Device: none
|
||||
Dependencies: pthreads, sprintf, logOutput, ???
|
||||
*/
|
||||
void runIO(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId)
|
||||
void runIO(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId, logFileLL *logList)
|
||||
{
|
||||
char timeStringy[MAX_STR_LEN];
|
||||
char ioOutput[MAX_STR_LEN];
|
||||
|
|
@ -630,12 +829,12 @@ void runIO(char *command, char *argument, int intArg, ConfigDataType *configPtr,
|
|||
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);
|
||||
logOutput(configPtr, ioOutput, false, logList);
|
||||
pthread_t ioThread;
|
||||
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);
|
||||
logOutput(configPtr, ioOutput, false, logList);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -648,7 +847,7 @@ Device Input/Device: none
|
|||
Device Output/Device: none
|
||||
Dependencies: accessTimer, compareString, runCPU, runIO, ???
|
||||
*/
|
||||
void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, ProcessControlBlockLL *pcbList)
|
||||
void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, ProcessControlBlockLL *pcbList, logFileLL *logList)
|
||||
{
|
||||
// run over the entire process, running the CPU when a CPU cycle comes up
|
||||
// or a run IO when an IO cycle comes up
|
||||
|
|
@ -673,12 +872,12 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce
|
|||
if (compareString(command, "cpu") == EQUIV && compareString(argument, "process") == EQUIV)
|
||||
{
|
||||
// run the CPU for the required amount of time.
|
||||
runCPU(workingMeta->command, workingMeta->strArg1, workingMeta->intArg2, configPtr, singlePCB->uniquePid);
|
||||
runCPU(workingMeta->command, workingMeta->strArg1, workingMeta->intArg2, configPtr, singlePCB->uniquePid, logList);
|
||||
}
|
||||
if(compareString(command, "dev") == EQUIV)
|
||||
{
|
||||
// run IO operations for the required amount of time.
|
||||
runIO(workingMeta->command, workingMeta->strArg1, workingMeta->intArg2, configPtr, singlePCB->uniquePid);
|
||||
runIO(workingMeta->command, workingMeta->strArg1, workingMeta->intArg2, configPtr, singlePCB->uniquePid, logList);
|
||||
}
|
||||
if(compareString(command, "mem") == EQUIV)
|
||||
{
|
||||
|
|
@ -686,27 +885,27 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce
|
|||
if(compareString(argument, "allocate") == EQUIV)
|
||||
{
|
||||
sprintf(processOutput, "%f, Process: %d, %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo);
|
||||
logOutput(configPtr, processOutput, false);
|
||||
logOutput(configPtr, processOutput, false, logList);
|
||||
// run the memory manager in allocate mode
|
||||
memManagerSuccess = memManager(pcbList, MEMORY_ALLOCATE, intArg, intArgTwo, configPtr, singlePCB);
|
||||
memManagerSuccess = memManager(pcbList, MEMORY_ALLOCATE, intArg, intArgTwo, configPtr, singlePCB, logList);
|
||||
if(!memManagerSuccess)
|
||||
{
|
||||
//
|
||||
sprintf(processOutput, "%f, Process: %d, failed %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo);
|
||||
logOutput(configPtr, processOutput, false);
|
||||
logOutput(configPtr, processOutput, false, logList);
|
||||
}
|
||||
}
|
||||
else if(compareString(argument, "access") == EQUIV)
|
||||
{
|
||||
sprintf(processOutput, "%f, Process: %d, %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo);
|
||||
logOutput(configPtr, processOutput, false);
|
||||
logOutput(configPtr, processOutput, false, logList);
|
||||
// run the memory manager in access mode
|
||||
memManagerSuccess = memManager(pcbList, MEMORY_ACCESS, intArg, intArgTwo, configPtr, singlePCB);
|
||||
memManagerSuccess = memManager(pcbList, MEMORY_ACCESS, intArg, intArgTwo, configPtr, singlePCB, logList);
|
||||
if (!memManagerSuccess)
|
||||
{
|
||||
//
|
||||
sprintf(processOutput, "%f, Process: %d, failed %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo);
|
||||
logOutput(configPtr, processOutput, false);
|
||||
logOutput(configPtr, processOutput, false, logList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -721,16 +920,16 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce
|
|||
{
|
||||
//
|
||||
sprintf(processOutput, "\n%f, OS: Process %d ended\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid);
|
||||
logOutput(configPtr, processOutput, false);
|
||||
logOutput(configPtr, processOutput, false, logList);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
sprintf(processOutput, "\n%f, OS: Segmentation Fault, Process %d ended\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid);
|
||||
logOutput(configPtr, processOutput, false);
|
||||
logOutput(configPtr, processOutput, false, logList);
|
||||
}
|
||||
// deallocate the memory for the process
|
||||
memManager(pcbList, MEMORY_DEALLOCATE, intArg, intArgTwo, configPtr, singlePCB);
|
||||
memManager(pcbList, MEMORY_DEALLOCATE, intArg, intArgTwo, configPtr, singlePCB, logList);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -753,6 +952,7 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
|||
// need a variable for headPointer to point
|
||||
ProcessControlBlockLL *pcbList;
|
||||
ProcessControlBlock *pcbPtr;
|
||||
logFileLL *loggingList;
|
||||
// string variable for nextCode, temp unused
|
||||
// char *nextCode;
|
||||
// string variable for the timer stuff
|
||||
|
|
@ -763,10 +963,13 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
|||
int memoryOffset = 0;
|
||||
int memorySize = 1;
|
||||
|
||||
// create the file list with createFileLogList, store the pointed to address
|
||||
loggingList = createFileLogList();
|
||||
|
||||
accessTimer(ZERO_TIMER, timeStringy);
|
||||
// Operating System start timer goes here, log it.
|
||||
sprintf(simulatorOutput, "%f, OS: Simulator start\n", accessTimer(LAP_TIMER, timeStringy));
|
||||
logOutput(configPtr, simulatorOutput, false);
|
||||
logOutput(configPtr, simulatorOutput, false, loggingList);
|
||||
// int variable for process to run
|
||||
int currentPid;
|
||||
// create the process list with createProcessList, store the pointed to address
|
||||
|
|
@ -795,10 +998,10 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
|||
int *processTimeLeftPtr = &processTimeLeft;
|
||||
|
||||
// set the current process id to the first scheduled process
|
||||
currentPid = scheduleProcess(pcbList, configPtr);
|
||||
currentPid = scheduleProcess(pcbList, configPtr, loggingList);
|
||||
|
||||
// initialize memory with the memManager
|
||||
memManager(pcbList, MEMORY_INITIALIZE, memoryOffset, memorySize, configPtr, pcbList->headPtr);
|
||||
memManager(pcbList, MEMORY_INITIALIZE, memoryOffset, memorySize, configPtr, pcbList->headPtr, loggingList);
|
||||
|
||||
// loop until current process is hit
|
||||
for(processIterator = 0; processIterator < processCount; processIterator++)
|
||||
|
|
@ -813,13 +1016,13 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
|||
// needs to set from READY to RUNNING
|
||||
pcbPtr->process_state = PROCESS_STATE_RUNNING;
|
||||
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, loggingList);
|
||||
pthread_t runThread;
|
||||
pthread_create(&runThread, NULL, runTimer, (void *)processTimeLeftPtr);
|
||||
runProcess(pcbPtr, configPtr, pcbList);
|
||||
runProcess(pcbPtr, configPtr, pcbList, loggingList);
|
||||
// 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);
|
||||
logOutput(configPtr, simulatorOutput, false);
|
||||
logOutput(configPtr, simulatorOutput, false, loggingList);
|
||||
pcbPtr->process_state = PROCESS_STATE_TERMINATED;
|
||||
pthread_join(runThread, NULL);
|
||||
}
|
||||
|
|
@ -827,20 +1030,22 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
|||
processTimeLeftPtr = &processTimeLeft;
|
||||
pcbPtr = pcbPtr->nextPtr;
|
||||
}
|
||||
currentPid = scheduleProcess(pcbList, configPtr);
|
||||
currentPid = scheduleProcess(pcbList, configPtr, loggingList);
|
||||
pcbPtr = pcbList->headPtr;
|
||||
}
|
||||
pthread_join(cpuThread, NULL);
|
||||
// deallocate all the memory for each process.
|
||||
memManager(pcbList, MEMORY_CLEAR, memoryOffset, memorySize, configPtr, pcbList->headPtr);
|
||||
memManager(pcbList, MEMORY_CLEAR, memoryOffset, memorySize, configPtr, pcbList->headPtr, loggingList);
|
||||
sprintf(simulatorOutput, "%f, OS: System Stop\n", accessTimer(LAP_TIMER, timeStringy));
|
||||
logOutput(configPtr, simulatorOutput, false);
|
||||
logOutput(configPtr, simulatorOutput, false, loggingList);
|
||||
sprintf(simulatorOutput, "%f, OS: Simulation End\n", accessTimer(LAP_TIMER, timeStringy));
|
||||
logOutput(configPtr, simulatorOutput, true);
|
||||
logOutput(configPtr, simulatorOutput, true, loggingList);
|
||||
// deallocate the process list with destroyProcessList
|
||||
destroyProcessList(pcbList);
|
||||
// once complete, log the output to FILE if required
|
||||
logOutput(configPtr, "", true);
|
||||
// logOutput(configPtr, "", true, loggingList);
|
||||
// deallocate the file log list with destroyFileLogList
|
||||
destroyFileLogList(loggingList);
|
||||
// pthread_exit(NULL); // this line seems to make the program execution stop short... no warning either
|
||||
// void function, no return.
|
||||
}
|
||||
|
|
@ -856,7 +1061,7 @@ Device Input/Device: none
|
|||
Device Output/Device: none
|
||||
Dependencies: sprintf, logOutput, ???
|
||||
*/
|
||||
int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPtr)
|
||||
int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPtr, logFileLL *logList)
|
||||
{
|
||||
ProcessControlBlock *wkgPtr;
|
||||
int returnPid = -1;
|
||||
|
|
@ -898,7 +1103,7 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt
|
|||
wkgPtr->process_state = PROCESS_STATE_READY;
|
||||
// printf("Process %d set to READY from NEW\n", wkgPtr->uniquePid);
|
||||
sprintf(loggingStr, "%f, OS: Process %d set to READY state from NEW state\n", accessTimer(LAP_TIMER, timeStringy), wkgPtr->uniquePid);
|
||||
logOutput(configPtr, loggingStr, false);
|
||||
logOutput(configPtr, loggingStr, false, logList);
|
||||
}
|
||||
// move to the next pointer
|
||||
wkgPtr = wkgPtr->nextPtr;
|
||||
|
|
@ -913,7 +1118,7 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt
|
|||
{
|
||||
//printf("Process %d Selected with %.0f ms remaining\n", wkgPtr->uniquePid, wkgPtr->timeLeft);
|
||||
sprintf(loggingStr, "%f, OS: Process %d selected with %.0f ms remaining\n", accessTimer(LAP_TIMER, timeStringy), wkgPtr->uniquePid, wkgPtr->timeLeft);
|
||||
logOutput(configPtr, loggingStr, false);
|
||||
logOutput(configPtr, loggingStr, false, logList);
|
||||
returnPid = wkgPtr->uniquePid;
|
||||
}
|
||||
// move to next pointer
|
||||
|
|
@ -941,7 +1146,7 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt
|
|||
wkgPtr->process_state = PROCESS_STATE_READY;
|
||||
// printf("Process %d set to READY from NEW\n", wkgPtr->uniquePid);
|
||||
sprintf(loggingStr, "%f, OS: Process %d set to READY state from NEW state\n", accessTimer(LAP_TIMER, timeStringy), wkgPtr->uniquePid);
|
||||
logOutput(configPtr, loggingStr, false);
|
||||
logOutput(configPtr, loggingStr, false, logList);
|
||||
}
|
||||
// move to the next pointer
|
||||
wkgPtr = wkgPtr->nextPtr;
|
||||
|
|
@ -992,7 +1197,7 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt
|
|||
{
|
||||
// printf("Process %d Selected with %.0f ms remaining\n", wkgPtr->uniquePid, wkgPtr->timeLeft);
|
||||
sprintf(loggingStr, "%f, OS: Process %d selected with %.0f ms remaining\n", accessTimer(LAP_TIMER, timeStringy), shortestJobProcNum, (double)shortestJob);
|
||||
logOutput(configPtr, loggingStr, false);
|
||||
logOutput(configPtr, loggingStr, false, logList);
|
||||
}
|
||||
returnPid = shortestJobProcNum;
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue