|
@@ -46,14 +46,11 @@ static car * newcar(Direction origin, Direction dest)
|
|
|
// push a car to the active array
|
|
|
static void push(car * newcar)
|
|
|
{
|
|
|
- //kprintf("first third: %d", *(dirs + newcar->origin));
|
|
|
- //kprintf("second third: %p", *(compass + newcar->origin));
|
|
|
- //kprintf("third third: %d", *(*(compass + newcar->origin) + newcar->dest));
|
|
|
// dirs + origin is our offset for where to start in the array
|
|
|
// compass + origin is the array we use to determine what to add to the first number
|
|
|
// newcar->dest gives the direction, which we use to find the offset indicating it's additive value
|
|
|
- int total = *(dirs + newcar->origin) + *(*(compass + newcar->origin) + newcar->dest);
|
|
|
- //kprintf("halfway through push\n");
|
|
|
+ int total = dirs[newcar->origin] + *(compass[newcar->origin] + newcar->dest);
|
|
|
+
|
|
|
// with our offset, set the pointer here to newcar
|
|
|
active[total] = newcar;
|
|
|
}
|
|
@@ -65,10 +62,7 @@ static void clearint(car * done)
|
|
|
// compass + origin is the array we use to determine what to add to the first number
|
|
|
// 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
|
|
|
- //kprintf("first third: %d", *(dirs + done->origin));
|
|
|
- //kprintf("second third: %p", *(compass + done->origin));
|
|
|
- //kprintf("third third: %d", *(*(compass + done->origin) + done->dest));
|
|
|
- int total = *(dirs + done->origin) + *(*(compass + done->origin) + done->dest);
|
|
|
+ int total = dirs[done->origin] + *(compass[done->origin] + done->dest);
|
|
|
active[total] = NULL;
|
|
|
|
|
|
if (done->cv) // if this car was blocking something
|
|
@@ -131,14 +125,12 @@ void intersection_before_entry(Direction origin, Direction destination)
|
|
|
car * new = newcar(origin, destination);
|
|
|
|
|
|
RESTART:
|
|
|
- //kprintf("starting the for loop for entering\n");
|
|
|
for (int i = 0; i < 12; ++i)
|
|
|
{
|
|
|
car * temp = active[i];
|
|
|
|
|
|
if (temp)
|
|
|
{
|
|
|
- //kprintf("temp at %d was not null\n", i);
|
|
|
if ((temp->origin == new->origin && temp->dest != new->dest) || (temp->origin == new->dest && temp->dest == new->origin) || (temp->dest != new->dest && (rightturn(new) || rightturn(temp))))
|
|
|
{
|
|
|
continue;
|
|
@@ -151,21 +143,17 @@ void intersection_before_entry(Direction origin, Direction destination)
|
|
|
temp->cv = cv_create("carcv");
|
|
|
}
|
|
|
|
|
|
- //kprintf("put something to sleep\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
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //kprintf("skipped %d because it was null\n", i);
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //kprintf("made it out of the for loop\n");
|
|
|
push(new);
|
|
|
- //kprintf("added a car to the int\n");
|
|
|
lock_release(globlock);
|
|
|
}
|
|
|
|
|
@@ -184,8 +172,7 @@ void intersection_before_entry(Direction origin, Direction destination)
|
|
|
void intersection_after_exit(Direction origin, Direction destination)
|
|
|
{
|
|
|
lock_acquire(globlock);
|
|
|
- int position = *(dirs + origin) + *(*(compass + origin) + destination);
|
|
|
+ int position = dirs[origin] + *(compass[origin] + destination);
|
|
|
clearint(active[position]);
|
|
|
- //kprintf("released a car from the int\n");
|
|
|
lock_release(globlock);
|
|
|
}
|