Skip to content
Snippets Groups Projects
Commit a975c620 authored by Elizabeth Baker's avatar Elizabeth Baker
Browse files

comments

parent f4584982
No related branches found
No related tags found
No related merge requests found
......@@ -49,6 +49,7 @@ void calStats(llist *completedProcesses, int *currentTime, float *aveTurnaroundT
void addProcessToQueue(llist *processQueue, process *newProcess, int currentTime, int cpuID);
process *getNextProcess(FILE *f, llist *arrivals, process *readAhead);
process *getNextProcessB(FILE *f, llist *arrivals, process *readAhead);
int main(int argc, char *argv[]) {
......@@ -107,7 +108,7 @@ int main(int argc, char *argv[]) {
//while (fgets(line, sizeof line, f) != NULL) {
while (newProcess = getNextProcess(f, arrivalLounge, readAhead)) {
while (newProcess = getNextProcessB(f, arrivalLounge, readAhead)) {
//printf("process id:%s process arrival time: %d\n", newProcess->processID, newProcess->timeArrived);
......@@ -484,14 +485,16 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
//add to arrivals until the readAhead is different
//memcpy(nextProcess,readAhead, sizeof(process));
llist_add_inorder(readAhead, arrivals, (int (*)(void *, void *)) &leastExecutionTime);
llist_print(arrivals,(void (*)(void *)) &printQEntry);
printf("readAhead: %s\n", readAhead->processID);
printf("New Process: %s\n", readAhead->processID);
printf("New Process: %s\n", newProcess->processID);
memcpy(readAhead,newProcess,sizeof(process));
printf("in if\n");
llist_print(arrivals,(void (*)(void *)) &printQEntry);
printf("readAhead: %s\n", readAhead->processID);
int count = 0;
llist_print(arrivals, (void (*)(void *)) &printQEntry);
while (newProcess->timeArrived == readAhead->timeArrived ){
//readAhead = nextProcess;
//memcpy(nextProcess,readAhead, sizeof(process));
......@@ -505,7 +508,7 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
if(fgets(line, sizeof line, f) == NULL){
printf("in while, end of file\n");
llist_print(arrivals,(void (*)(void *)) &printQEntry);
readAhead->timeArrived = -1;
readAhead->timeArrived = -1; // Flag EOF
return llist_pop(arrivals);
}
initializeProcess(line,newProcess);
......@@ -513,7 +516,7 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
printf("New Process: %s\n", readAhead->processID);
}
llist_print(arrivals, (void (*)(void *)) &printQEntry);
// llist_print(arrivals, (void (*)(void *)) &printQEntry);
//readAhead = nextProcess;
memcpy(readAhead,nextProcess,sizeof(process));
......@@ -530,3 +533,35 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
}
process *getNextProcessB(FILE *f, llist *arrivals, process *readAhead) {
char line[36];
process *newProcess;
int batchEnd;
if (arrivals != NULL) {
if (headData(arrivals) == NULL) {// no buffered processes so...{
// queue the next batch of arrivals - starting with the read ahead.
newProcess = malloc(sizeof(process));
memcpy(newProcess, readAhead, sizeof(process));
llist_add_inorder(newProcess, arrivals, (int (*)(void *, void *)) &leastExecutionTime);
while (readAhead->timeArrived != -1 && !batchEnd) {
if (fgets(line, sizeof line, f) != NULL) {
initializeProcess(line, newProcess);
if (newProcess->timeArrived == readAhead->timeArrived) {
llist_add_inorder(newProcess, arrivals, (int (*)(void *, void *)) &leastExecutionTime);
} else {
batchEnd = -1;
memcpy(readAhead, newProcess, sizeof(process));
}
} else {
readAhead->timeArrived = -1;
}
}
}
// now there's stuff in the arrivals lounge or there are no more to arrive
}
llist_print(arrivals, (void (*)(void *)) &printQEntry);
return llist_pop(arrivals);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment