Methods Summary |
---|
private synchronized int | findNextSlot()
for (int i = 0; i < MAX_CAPACITY; i++) {
if (sleepFor[i] == UNUSED)
return i;
}
return NOROOM;
|
public synchronized boolean | letMeSleepFor(Sleeper s, long time)
int index = findNextSlot();
if (index == NOROOM) {
return false;
} else {
sleepers[index] = s;
sleepFor[index] = time;
new AlarmThread(index).start();
return true;
}
|
private synchronized void | wakeUpSleeper(int sleeperIndex)
sleepers[sleeperIndex].wakeUp();
sleepers[sleeperIndex] = null;
sleepFor[sleeperIndex] = UNUSED;
|