]> Devi Nivas Git - cs3210-lab0.git/commitdiff
check p->killed for long-lived sleeps
authorrsc <rsc>
Wed, 8 Aug 2007 10:29:42 +0000 (10:29 +0000)
committerrsc <rsc>
Wed, 8 Aug 2007 10:29:42 +0000 (10:29 +0000)
console.c
pipe.c
proc.c

index ec3ecd06f42ee359a2345c3c72223d324e2c274e..cd52570606c6ca12071f10f32151efee96617aef 100644 (file)
--- a/console.c
+++ b/console.c
@@ -6,6 +6,7 @@
 #include "dev.h"
 #include "param.h"
 #include "mmu.h"
+#include "proc.h"
 
 struct spinlock console_lock;
 int panicked = 0;
@@ -395,8 +396,13 @@ console_read(int minor, char *dst, int n)
   target = n;
   acquire(&kbd_lock);
   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);
+    }
     c = kbd_buf[kbd_r++];
     if(c == C('D')){  // EOF
       if(n < target){
diff --git a/pipe.c b/pipe.c
index 7ef89e2ea3de83f523de1cd671498bde84ed7749..923e609dfaf4ed9c4cc26a4bd2b4ab25fad4dcf7 100644 (file)
--- a/pipe.c
+++ b/pipe.c
@@ -86,7 +86,7 @@ pipe_write(struct pipe *p, char *addr, int n)
 
   for(i = 0; i < n; i++){
     while(((p->writep + 1) % PIPESIZE) == p->readp){
-      if(p->readopen == 0){
+      if(p->readopen == 0 || curproc[cpu()]->killed){
         release(&p->lock);
         return -1;
       }
@@ -110,7 +110,7 @@ pipe_read(struct pipe *p, char *addr, int n)
   acquire(&p->lock);
 
   while(p->readp == p->writep){
-    if(p->writeopen == 0){
+    if(p->writeopen == 0 || curproc[cpu()]->killed){
       release(&p->lock);
       return 0;
     }
diff --git a/proc.c b/proc.c
index 96f96d922a7696e09f8e25ab460fd1d6770d805e..37adbb440a035fbd324aba5af4a4978df88a892f 100644 (file)
--- a/proc.c
+++ b/proc.c
@@ -405,7 +405,7 @@ proc_wait(void)
     }
 
     // No point waiting if we don't have any children.
-    if(!havekids){
+    if(!havekids || cp->killed){
       release(&proc_table_lock);
       return -1;
     }