|
@@ -16,7 +16,7 @@ typedef struct car
|
|
|
} car;
|
|
|
|
|
|
// array of all 12 possible cars in the intersection
|
|
|
-car ** active = NULL;
|
|
|
+car * active[12] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
|
|
|
|
|
|
// all of our offset arrays
|
|
|
int dirs[4] = {0, 3, 6, 9};
|
|
@@ -43,22 +43,6 @@ static car * newcar(Direction origin, Direction dest)
|
|
|
return temp;
|
|
|
}
|
|
|
|
|
|
-// initialize the array active
|
|
|
-static void activeinit(void)
|
|
|
-{
|
|
|
- active = kmalloc(12 * sizeof(car *));
|
|
|
-
|
|
|
- if (!(active))
|
|
|
- {
|
|
|
- panic("Failed to create an array");
|
|
|
- }
|
|
|
-
|
|
|
- for (int i = 0; i < 12; ++i)
|
|
|
- {
|
|
|
- *(active + i) = NULL;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
// push a car to the active array
|
|
|
static void push(car * newcar)
|
|
|
{
|
|
@@ -71,7 +55,7 @@ static void push(car * newcar)
|
|
|
int total = *(dirs + newcar->origin) + *(*(compass + newcar->origin) + newcar->dest);
|
|
|
//kprintf("halfway through push\n");
|
|
|
// with our offset, set the pointer here to newcar
|
|
|
- *(active + total) = newcar;
|
|
|
+ active[total] = newcar;
|
|
|
}
|
|
|
|
|
|
// called when a car clears the intersection
|
|
@@ -85,7 +69,7 @@ static void clearint(car * done)
|
|
|
//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);
|
|
|
- *(active + total) = NULL;
|
|
|
+ active[total] = NULL;
|
|
|
|
|
|
if (done->cv) // if this car was blocking something
|
|
|
{
|
|
@@ -96,12 +80,6 @@ static void clearint(car * done)
|
|
|
kfree(done);
|
|
|
}
|
|
|
|
|
|
-// delete active array, offset calculation arrays
|
|
|
-static void cleanup()
|
|
|
-{
|
|
|
- kfree(active);
|
|
|
-}
|
|
|
-
|
|
|
// returns true if a car is turning right
|
|
|
static bool rightturn(car * car)
|
|
|
{
|
|
@@ -118,11 +96,6 @@ void intersection_sync_init()
|
|
|
{
|
|
|
panic("Failed to create lock!\n");
|
|
|
}
|
|
|
-
|
|
|
- // initilaize array of active cars
|
|
|
- activeinit();
|
|
|
-
|
|
|
- //kprintf("finished init steps\n");
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -135,7 +108,6 @@ void intersection_sync_init()
|
|
|
void intersection_sync_cleanup()
|
|
|
{
|
|
|
KASSERT(active);
|
|
|
- cleanup();
|
|
|
lock_destroy(globlock);
|
|
|
}
|
|
|
|
|
@@ -162,7 +134,7 @@ void intersection_before_entry(Direction origin, Direction destination)
|
|
|
//kprintf("starting the for loop for entering\n");
|
|
|
for (int i = 0; i < 12; ++i)
|
|
|
{
|
|
|
- car * temp = *(active + i);
|
|
|
+ car * temp = active[i];
|
|
|
|
|
|
if (temp)
|
|
|
{
|
|
@@ -213,7 +185,7 @@ void intersection_after_exit(Direction origin, Direction destination)
|
|
|
{
|
|
|
lock_acquire(globlock);
|
|
|
int position = *(dirs + origin) + *(*(compass + origin) + destination);
|
|
|
- clearint(*(active + position));
|
|
|
+ clearint(active[position]);
|
|
|
//kprintf("released a car from the int\n");
|
|
|
lock_release(globlock);
|
|
|
}
|