|
@@ -40,7 +40,6 @@ typedef struct list
|
|
|
car * back;
|
|
|
} list;
|
|
|
|
|
|
-list * queue = NULL;
|
|
|
list * active = NULL;
|
|
|
|
|
|
// car initializer/allocator
|
|
@@ -78,28 +77,6 @@ static list * newlist()
|
|
|
return temp;
|
|
|
}
|
|
|
|
|
|
-// puts a car into the queue, at the front if old is true, the back otherwise
|
|
|
-static void enqueue(car * newcar)
|
|
|
-{
|
|
|
- if (!(queue->back))
|
|
|
- {
|
|
|
- queue->front = newcar;
|
|
|
- queue->back = newcar;
|
|
|
- }
|
|
|
-
|
|
|
- if (newcar->old) // if the car is "old", let it go first. be nice to your elders
|
|
|
- {
|
|
|
- car * temp = queue->front;
|
|
|
- queue->front = newcar;
|
|
|
- newcar->next = temp;
|
|
|
-
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- queue->back->next = newcar;
|
|
|
- queue->back = newcar;
|
|
|
-}
|
|
|
-
|
|
|
// push a car to the end of the active list
|
|
|
static void push(car * newcar)
|
|
|
{
|
|
@@ -113,24 +90,6 @@ static void push(car * newcar)
|
|
|
active->back = newcar;
|
|
|
}
|
|
|
|
|
|
-// remove an element from the front of the queue
|
|
|
-static car * pop()
|
|
|
-{
|
|
|
- if (!(queue->front))
|
|
|
- {
|
|
|
- return NULL;
|
|
|
- }
|
|
|
-
|
|
|
- if (queue->front == queue->back)
|
|
|
- {
|
|
|
- queue->back == NULL;
|
|
|
- }
|
|
|
-
|
|
|
- car * temp = queue->front;
|
|
|
- queue->front = queue->front->next;
|
|
|
- return temp;
|
|
|
-}
|
|
|
-
|
|
|
// called when a car clears the intersection
|
|
|
static void clearint(car * done)
|
|
|
{
|
|
@@ -140,7 +99,7 @@ static void clearint(car * done)
|
|
|
while(temp != done)
|
|
|
{
|
|
|
temp2 = temp;
|
|
|
- temp = temp>next;
|
|
|
+ temp = temp->next;
|
|
|
}
|
|
|
|
|
|
// first element of the list is being removed
|
|
@@ -201,7 +160,6 @@ void intersection_sync_init()
|
|
|
panic("Failed to create lock!");
|
|
|
}
|
|
|
|
|
|
- queue = newlist();
|
|
|
active = newlist();
|
|
|
}
|
|
|
|
|
@@ -214,10 +172,8 @@ void intersection_sync_init()
|
|
|
*/
|
|
|
void intersection_sync_cleanup()
|
|
|
{
|
|
|
- KASSERT(queue);
|
|
|
KASSERT(active);
|
|
|
|
|
|
- dellist(queue);
|
|
|
dellist(active);
|
|
|
lock_destroy(globlock);
|
|
|
}
|
|
@@ -263,7 +219,6 @@ void intersection_before_entry(Direction origin, Direction destination)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- enqueue(new);
|
|
|
new->old = 1; // make new "old", since now it has already waited once
|
|
|
lock_release(globlock);
|
|
|
|