check p->killed for long-lived sleeps
This commit is contained in:
parent
1cb183a987
commit
f2f062da61
|
@ -6,6 +6,7 @@
|
||||||
#include "dev.h"
|
#include "dev.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "mmu.h"
|
#include "mmu.h"
|
||||||
|
#include "proc.h"
|
||||||
|
|
||||||
struct spinlock console_lock;
|
struct spinlock console_lock;
|
||||||
int panicked = 0;
|
int panicked = 0;
|
||||||
|
@ -395,8 +396,13 @@ console_read(int minor, char *dst, int n)
|
||||||
target = n;
|
target = n;
|
||||||
acquire(&kbd_lock);
|
acquire(&kbd_lock);
|
||||||
while(n > 0){
|
while(n > 0){
|
||||||
while(kbd_r == kbd_w)
|
while(kbd_r == kbd_w){
|
||||||
|
if(curproc[cpu()]->killed){
|
||||||
|
release(&kbd_lock);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
sleep(&kbd_r, &kbd_lock);
|
sleep(&kbd_r, &kbd_lock);
|
||||||
|
}
|
||||||
c = kbd_buf[kbd_r++];
|
c = kbd_buf[kbd_r++];
|
||||||
if(c == C('D')){ // EOF
|
if(c == C('D')){ // EOF
|
||||||
if(n < target){
|
if(n < target){
|
||||||
|
|
4
pipe.c
4
pipe.c
|
@ -86,7 +86,7 @@ pipe_write(struct pipe *p, char *addr, int n)
|
||||||
|
|
||||||
for(i = 0; i < n; i++){
|
for(i = 0; i < n; i++){
|
||||||
while(((p->writep + 1) % PIPESIZE) == p->readp){
|
while(((p->writep + 1) % PIPESIZE) == p->readp){
|
||||||
if(p->readopen == 0){
|
if(p->readopen == 0 || curproc[cpu()]->killed){
|
||||||
release(&p->lock);
|
release(&p->lock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ pipe_read(struct pipe *p, char *addr, int n)
|
||||||
acquire(&p->lock);
|
acquire(&p->lock);
|
||||||
|
|
||||||
while(p->readp == p->writep){
|
while(p->readp == p->writep){
|
||||||
if(p->writeopen == 0){
|
if(p->writeopen == 0 || curproc[cpu()]->killed){
|
||||||
release(&p->lock);
|
release(&p->lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue