From fb8555d1d79ed3c5282b1a338918bf6bb437117b Mon Sep 17 00:00:00 2001 From: bakere1 <bakere1@student.unimelb.edu.au> Date: Sun, 28 Mar 2021 17:23:47 +1100 Subject: [PATCH] comments --- allocate.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/allocate.c b/allocate.c index 5978b11..e929108 100644 --- a/allocate.c +++ b/allocate.c @@ -81,15 +81,18 @@ int main(int argc, char *argv[]) { } } + // Initialize input file and arrival queue char line[36]; arrivalLounge = llist_create(NULL); FILE *f = fopen(file, "r"); process *headProcess; process *readAhead = malloc(sizeof(process)); + // read the first process in if (fgets(line, sizeof line, f) != NULL) { //initialize the first process just read initializeProcess(line, readAhead); - } + } else readAhead->timeArrived = -1; // use -1 arrival to flag EOF + //initialize CPUs CPU *CPUs = malloc(numCPU * sizeof(CPU)); for (int i = 0; i < numCPU; i++) { @@ -454,8 +457,9 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) { //checking if at the end of the file if (fgets(line, sizeof line, f) == NULL && readAhead->timeArrived != -1 ) { //read EOF && readAhead != NULL - memcpy(nextProcess,readAhead, sizeof(process)); - llist_add_inorder(nextProcess, arrivals, (int (*)(void *, void *)) &leastExecutionTime); +// memcpy(nextProcess,readAhead, sizeof(process)); +// llist_add_inorder(nextProcess, arrivals, (int (*)(void *, void *)) &leastExecutionTime); + llist_add_inorder(readAhead, arrivals, (int (*)(void *, void *)) &leastExecutionTime); readAhead->timeArrived = -1; //free(readAhead); //initializeProcess(NULL,readAhead); -- GitLab