Jelajahi Sumber

ready to show to prof

tarfeef101 6 tahun lalu
induk
melakukan
5b113eefc0
1 mengubah file dengan 12 tambahan dan 9 penghapusan
  1. 12 9
      kern/synchprobs/traffic_synch.c

+ 12 - 9
kern/synchprobs/traffic_synch.c

@@ -2,7 +2,7 @@
 #include <lib.h>
 #include <synchprobs.h>
 #include <synch.h>
-#include <wchan.h>
+//#include <wchan.h>
 #include <opt-A1.h>
 
 /*
@@ -79,6 +79,7 @@ static list * newlist()
 // push a car to the end of the active list
 static void push(car * newcar)
 {
+  // empty list
   if (!(active->front))
   {
     active->front = newcar;
@@ -96,6 +97,7 @@ static void clearint(car * done)
   car * temp = active->front;
   car * temp2 = NULL;
   
+  // loop through until we match, storing the parent element
   while(temp != done)
   {
     temp2 = temp;
@@ -121,15 +123,15 @@ static void clearint(car * done)
   
   if (temp->cv) // if this car was blocking something
   {
-    //cv_broadcast(temp->cv, globlock); // wake all/inform them you're all good
-    //cv_destroy(temp->cv);
+    cv_broadcast(temp->cv, globlock); // wake all/inform them you're all good
+    cv_destroy(temp->cv);
     
-    while (!(wchan_isempty(temp->cv->wc)))
+    /*while (!(wchan_isempty(temp->cv->wc)))
     {
       cv_signal(temp->cv, globlock);
     }
     
-    cv_destroy(temp->cv);
+    cv_destroy(temp->cv);*/
   }
   
   kfree(temp);
@@ -139,7 +141,7 @@ static void clearint(car * done)
 static void dellist(list * dead)
 {
   car * temp = dead->front;
-  
+
   while (temp)
   {
     car * temp2 = temp->next;
@@ -226,10 +228,10 @@ void intersection_before_entry(Direction origin, Direction destination)
     
     while (temp)
     {
-      kprintf("New o: %d, Comp o: %d, New d: %d, Comp d: %d\n", new->origin, temp->origin, new->dest, temp->dest);
+      //kprintf("New o: %d, Comp o: %d, New d: %d, Comp d: %d\n", new->origin, temp->origin, new->dest, temp->dest);
       if (temp->origin == new->origin || (temp->origin == new->dest && temp->dest == new->origin) || (temp->dest != new->dest && (rightturn(new) || rightturn(temp))))
       {
-        kprintf("Everything is fine, continue\n");
+        //kprintf("Everything is fine, continue\n");
         temp = temp->next;
         continue;
       }
@@ -241,7 +243,7 @@ void intersection_before_entry(Direction origin, Direction destination)
           temp->cv = cv_create("carcv");
         }
         
-        kprintf("actually sleeping now\n");
+        //kprintf("actually sleeping now\n");
         cv_wait(temp->cv, globlock); // sleep and reacquire lock once woken
         goto RESTART; // now we have to make sure there's nothing else screwing us over
       }
@@ -269,6 +271,7 @@ void intersection_after_exit(Direction origin, Direction destination)
   lock_acquire(globlock);
   car * temp = active->front;
   
+  // since this is a list we append to, loop through and stop on first match
   while (temp)
   {
     if (temp->origin == origin && temp->dest == destination)