-
-
-
CENAPAD-MGCO
A seguir: Camas
Acima: Chaves e Camas
Anterior: Chaves e Camas
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();
/* lock pode ser chamada por processos com interrupcoes
inibidas ou nao, e por isto o status \'{e} restabelecido
*/
}
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();
}