소스 검색

working, but slow. and also collisions occur sometimes

tsdedhar 6 년 전
부모
커밋
8e5ac8e229
1개의 변경된 파일4개의 추가작업 그리고 3개의 파일을 삭제
  1. 4 3
      kern/synchprobs/traffic_synch.c

+ 4 - 3
kern/synchprobs/traffic_synch.c

@@ -116,12 +116,10 @@ static void clearint(car * done)
   
   temp2->next = temp->next;
   SKIP1:
-  
+
   if (temp->cv) // if this car was blocking something
   {
-    lock_acquire(globlock);
     cv_broadcast(temp->cv, globlock); // wake all/inform them you're all good
-    lock_release(globlock);
     cv_destroy(temp->cv);
   }
   
@@ -256,6 +254,7 @@ void intersection_before_entry(Direction origin, Direction destination)
 
 void intersection_after_exit(Direction origin, Direction destination)
 {
+  lock_acquire(globlock);
   car * temp = active->front;
   
   while (temp)
@@ -270,4 +269,6 @@ void intersection_after_exit(Direction origin, Direction destination)
       temp = temp->next;
     }
   }
+
+  lock_release(globlock);
 }