next up previous
Next: Camas Up: Chaves e Camas Previous: Chaves e Camas

Chaves

 
class Key {

boolean locked;

Queue waiting;

}

void lock(Key k) {

InterruptStatus is = saveInterruptStatus(); disableInterrupts();

if(k.locked) {

k.waiting.put(currentProcess);

currentProcess.state = WAITING;

transfer(currentProcess.coroutine, kernel);

}

k.locked = true;

is.restore();

}

void unlock(Key k) {

InterruptStatus is = saveInterruptStatus(); disableInterrupts();

if(k.waiting.empty()) {

k.locked = false;

} else {

Process p = k.waiting.get();

p.state = READY;

ready.put(p);

}

is.restore();

}



Osvaldo Sergio F. de Carvalho
Wed Mar 19 14:56:39 EST 1997