From 57d8137911a761a636230d03a8118add48104ec8 Mon Sep 17 00:00:00 2001
From: Bess <bakere1@student.unimelb.edu.au>
Date: Sun, 28 Mar 2021 17:12:00 +1100
Subject: [PATCH] buffProc -not for task4 test 2

---
 allocate.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/allocate.c b/allocate.c
index 96c1b2f..f2b644d 100644
--- a/allocate.c
+++ b/allocate.c
@@ -9,6 +9,8 @@
 #include "llist.c"
 #include "llist.h"
 
+#define INT_MAX __INT_MAX__
+
 typedef struct {
     int timeArrived;
     int timeCompleted; //instant of time completed
@@ -221,7 +223,7 @@ int main(int argc, char *argv[]) {
                 // printf("current time: %d\n", currentTime);
                 headProcess->justStarted = 0;
                 printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n",
-                       currentTime - deltaTime, headProcess->processID, headProcess->timeRemaining, j);
+                       currentTime, headProcess->processID, headProcess->timeRemaining, j);
             }
         }
 
@@ -455,7 +457,7 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
         memcpy(nextProcess,readAhead, sizeof(process));
         llist_add_inorder(nextProcess, arrivals, (int (*)(void *, void *)) &leastExecutionTime);
         readAhead->timeArrived = -1;
-        free(readAhead);
+        //free(readAhead);
         //initializeProcess(NULL,readAhead);
         if (headData(arrivals) != NULL) { //have read EOF but still arrivals
             return llist_pop(arrivals);
@@ -474,19 +476,31 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
     if(headProcess == NULL){//no one in the arrivals lounge
         //same start time
         if(newProcess->timeArrived == readAhead->timeArrived){
-            //add to arrivals until  the readAhead is different
+            //add to arrivals until the readAhead is different
+            //memcpy(nextProcess,readAhead, sizeof(process));
             llist_add_inorder(readAhead, arrivals, (int (*)(void *, void *)) &leastExecutionTime);
-            while (newProcess->timeArrived == readAhead->timeArrived){
-                readAhead = nextProcess;
+            memcpy(readAhead,newProcess,sizeof(process));
+            int count = 0;
+            while (newProcess->timeArrived == readAhead->timeArrived ){
+                //readAhead = nextProcess;
+                //memcpy(nextProcess,readAhead, sizeof(process));
+                if(count > 0){
+                    llist_add_inorder(readAhead, arrivals, (int (*)(void *, void *)) &leastExecutionTime);
+                    memcpy(readAhead, newProcess, sizeof(process));
+                }
+
                 //EOF the file assign readAhead to null then return pop(arrivals)
                 if(fgets(line, sizeof line, f) == NULL){
                     readAhead->timeArrived = -1;
                     return llist_pop(arrivals);
                 }
                 initializeProcess(line,newProcess);
-                llist_add_inorder(readAhead, arrivals, (int (*)(void *, void *)) &leastExecutionTime);
+                count +1;
             }
-            readAhead = nextProcess;
+            llist_print(arrivals, (void (*)(void *)) &printQEntry);
+
+            //readAhead = nextProcess;
+            memcpy(readAhead,nextProcess,sizeof(process));
             //if the readAhead is differnt
             return llist_pop(arrivals);
         } else{//diff start time
-- 
GitLab