Преглед изворни кода

i totally remember how to pointer

tarfeef101 пре 6 година
родитељ
комит
39f79e8384
1 измењених фајлова са 7 додато и 7 уклоњено
  1. 7 7
      kern/synchprobs/traffic_synch.c

+ 7 - 7
kern/synchprobs/traffic_synch.c

@@ -17,7 +17,7 @@ typedef struct car
 } car;
 
 // array of all 12 possible cars in the intersection
-car * active = NULL;
+car ** active = NULL;
 
 // all of our offset arrays
 int * dirs;
@@ -45,7 +45,7 @@ static car * newcar(Direction origin, Direction dest)
 }
 
 // initialize the array active
-void activeinit(void)
+static void activeinit(void)
 {
   active = kmalloc(12 * sizeof(car *));
   
@@ -56,7 +56,7 @@ void activeinit(void)
   
   for (int i = 0; i < 12; ++i)
   {
-    active + i = NULL;
+    *(active + i) = NULL;
   }
 }
 
@@ -69,7 +69,7 @@ static void push(car * newcar)
   int total = *(dirs + newcar->origin) + *(*(compass + newcar->origin) + newcar->dest);
   
   // with our offset, set the pointer here to newcar
-  active + total = newcar;
+  *(active + total) = newcar;
 }
 
 // called when a car clears the intersection
@@ -80,7 +80,7 @@ static void clearint(car * done)
   // newcar->dest gives the direction, which we use to find the offset indicating it's additive value
   // set the array of active cars to null at this value
   int total = *(dirs + done->origin) + *(*(compass + done->origin) + done->dest);
-  active + total = NULL;
+  *(active + total) = NULL;
   
   if (done->cv) // if this car was blocking something
   {
@@ -211,7 +211,7 @@ void intersection_before_entry(Direction origin, Direction destination)
   
   for (int i = 0; i < 12; ++i)
   {
-    car * temp = active + i;
+    car * temp = *(active + i);
     
     if (temp)
     {
@@ -258,6 +258,6 @@ void intersection_after_exit(Direction origin, Direction destination)
 {
   lock_acquire(globlock);
   int position = *(dirs + origin) + *(*(compass + origin) + destination);
-  clearint(active + position);
+  clearint(*(active + position));
   lock_release(globlock);
 }