summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2019-07-07 14:57:16 -0400
committerRobert Morris <[email protected]>2019-07-07 14:57:16 -0400
commit4ce3a5fa21bc1ecda7b833a0f8fb05cdcd6d3a67 (patch)
treea32292dba538f0bf462eec09e2577d42d30498cf /kernel
parentc4f6a241cdc220dafe01bc7ca2ca7f8a253a838c (diff)
downloadxv6-labs-4ce3a5fa21bc1ecda7b833a0f8fb05cdcd6d3a67.tar.gz
xv6-labs-4ce3a5fa21bc1ecda7b833a0f8fb05cdcd6d3a67.tar.bz2
xv6-labs-4ce3a5fa21bc1ecda7b833a0f8fb05cdcd6d3a67.zip
nits
Diffstat (limited to 'kernel')
-rw-r--r--kernel/proc.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/kernel/proc.c b/kernel/proc.c
index cfb3262..44bacc2 100644
--- a/kernel/proc.c
+++ b/kernel/proc.c
@@ -76,8 +76,9 @@ allocpid() {
//PAGEBREAK: 32
// Look in the process table for an UNUSED proc.
-// If found, change state to EMBRYO and initialize
-// state required to run in the kernel.
+// If found, change state to EMBRYO, initialize
+// state required to run in the kernel,
+// and return with p->lock held.
// Otherwise return 0.
static struct proc*
allocproc(void)
@@ -124,7 +125,7 @@ found:
// free a proc structure and the data hanging from it,
// including user pages.
-// the proc lock must be held.
+// p->lock must be held.
static void
freeproc(struct proc *p)
{
@@ -259,6 +260,7 @@ fork(void)
// Copy user memory from parent to child.
if(uvmcopy(p->pagetable, np->pagetable, p->sz) < 0){
freeproc(np);
+ release(&np->lock);
return -1;
}
np->sz = p->sz;
@@ -290,9 +292,10 @@ fork(void)
// Pass p's abandoned children to init. p and p's parent
// are locked.
-void reparent(struct proc *p, struct proc *parent) {
+void
+reparent(struct proc *p, struct proc *parent) {
struct proc *pp;
- int init_is_my_parent = (p->parent == initproc);
+ int child_of_init = (p->parent == initproc);
for(pp = ptable.proc; pp < &ptable.proc[NPROC]; pp++){
if (pp != p && pp != parent) {
@@ -300,10 +303,10 @@ void reparent(struct proc *p, struct proc *parent) {
if(pp->parent == p){
pp->parent = initproc;
if(pp->state == ZOMBIE) {
- if(!init_is_my_parent)
+ if(!child_of_init)
acquire(&initproc->lock);
wakeup1(initproc);
- if(!init_is_my_parent)
+ if(!child_of_init)
release(&initproc->lock);
}
}
@@ -431,10 +434,8 @@ scheduler(void)
// Process is done running for now.
// It should have changed its p->state before coming back.
c->proc = 0;
- release(&p->lock);
- } else {
- release(&p->lock);
}
+ release(&p->lock);
}
}
}