]> Devi Nivas Git - cs3210-lab1.git/commitdiff
move everything having to do with proc_table_lock into proc.c
authorrsc <rsc>
Sat, 15 Jul 2006 17:24:54 +0000 (17:24 +0000)
committerrsc <rsc>
Sat, 15 Jul 2006 17:24:54 +0000 (17:24 +0000)
defs.h
picirq.c
proc.c
syscall.c

diff --git a/defs.h b/defs.h
index 3a07ed2fc3866db1f6b62fbf974edcf21f7aea38..dc8a831e3b4f8f68e0e9f393a258a27907e42e1e 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -19,6 +19,8 @@ void sleep(void *, struct spinlock *);
 void wakeup(void *);
 void scheduler(void);
 void proc_exit(void);
+int proc_kill(int);
+int proc_wait(void);
 void yield(void);
 void cli(void);
 void sti(void);
index 9c3ea0c37d265fab60e3337a54cac03d00ffbcff..19c4f88ac036a8b2a82173f573a164f37e2654da 100644 (file)
--- a/picirq.c
+++ b/picirq.c
@@ -53,7 +53,7 @@ pic_init(void)
   outb(IO_PIC2+1, IRQ_SLAVE);          // ICW3
   // NB Automatic EOI mode doesn't tend to work on the slave.
   // Linux source code says it's "to be investigated".
-  outb(IO_PIC2+1, 0x3);                        // ICW4
+  outb(IO_PIC2+1, 0x1);                        // ICW4
 
   // OCW3:  0ef01prs
   //   ef:  0x = NOP, 10 = clear specific mask, 11 = set specific mask
diff --git a/proc.c b/proc.c
index e69f1d102b8a7cb3613e149d6646ea9347fdc52c..76ec64e7b45b388b85c049c323f62cacb8e7bf4d 100644 (file)
--- a/proc.c
+++ b/proc.c
@@ -281,6 +281,56 @@ proc_exit()
   panic("a zombie revived");
 }
 
+int
+proc_wait(void)
+{
+  struct proc *p;
+  struct proc *cp = curproc[cpu()];
+  int any, pid;
+
+  acquire(&proc_table_lock);
+
+  while(1){
+    any = 0;
+    for(p = proc; p < &proc[NPROC]; p++){
+      if(p->state == ZOMBIE && p->ppid == cp->pid){
+        kfree(p->mem, p->sz);
+        kfree(p->kstack, KSTACKSIZE);
+        pid = p->pid;
+        p->state = UNUSED;
+        release(&proc_table_lock);
+        return pid;
+      }
+      if(p->state != UNUSED && p->ppid == cp->pid)
+        any = 1;
+    }
+    if(any == 0){
+      release(&proc_table_lock);
+      return -1;
+    }
+    sleep(cp, &proc_table_lock);
+  }
+}
+
+int
+proc_kill(int pid)
+{
+  struct proc *p;
+
+  acquire(&proc_table_lock);
+  for(p = proc; p < &proc[NPROC]; p++){
+    if(p->pid == pid && p->state != UNUSED){
+      p->killed = 1;
+      if(p->state == WAITING)
+        p->state = RUNNABLE;
+      release(&proc_table_lock);
+      return 0;
+    }
+  }
+  release(&proc_table_lock);
+  return -1;
+}
+
 // disable interrupts
 void
 cli(void)
index 0b49ff9230831505688f5bd34cdbc7ba88e1034b..e03901d44773a71713f80b7fd2756f9f4413f33d 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -162,38 +162,22 @@ int
 sys_exit(void)
 {
   proc_exit();
-  return 0;
+  return 0;  // not reached
 }
 
 int
 sys_wait(void)
 {
-  struct proc *p;
-  struct proc *cp = curproc[cpu()];
-  int any, pid;
+  return proc_wait();
+}
 
-  acquire(&proc_table_lock);
+int
+sys_kill(void)
+{
+  int pid;
 
-  while(1){
-    any = 0;
-    for(p = proc; p < &proc[NPROC]; p++){
-      if(p->state == ZOMBIE && p->ppid == cp->pid){
-        kfree(p->mem, p->sz);
-        kfree(p->kstack, KSTACKSIZE);
-        pid = p->pid;
-        p->state = UNUSED;
-        release(&proc_table_lock);
-        return pid;
-      }
-      if(p->state != UNUSED && p->ppid == cp->pid)
-        any = 1;
-    }
-    if(any == 0){
-      release(&proc_table_lock);
-      return -1;
-    }
-    sleep(cp, &proc_table_lock);
-  }
+  fetcharg(0, &pid);
+  return proc_kill(pid);
 }
 
 int
@@ -231,27 +215,6 @@ sys_block(void)
   return 0;
 }
 
-int
-sys_kill(void)
-{
-  int pid;
-  struct proc *p;
-
-  fetcharg(0, &pid);
-  acquire(&proc_table_lock);
-  for(p = proc; p < &proc[NPROC]; p++){
-    if(p->pid == pid && p->state != UNUSED){
-      p->killed = 1;
-      if(p->state == WAITING)
-        p->state = RUNNABLE;
-      release(&proc_table_lock);
-      return 0;
-    }
-  }
-  release(&proc_table_lock);
-  return -1;
-}
-
 int
 sys_panic(void)
 {