holding p->lock all the way through state=RUNNABLE means we don't need EMBRYO

This commit is contained in:
Robert Morris 2019-07-08 11:11:00 -04:00
parent db72f3108f
commit 9d34838b4f
2 changed files with 7 additions and 12 deletions

View file

@ -75,8 +75,7 @@ allocpid() {
//PAGEBREAK: 32 //PAGEBREAK: 32
// Look in the process table for an UNUSED proc. // Look in the process table for an UNUSED proc.
// If found, change state to EMBRYO, initialize // If found, initialize state required to run in the kernel,
// state required to run in the kernel,
// and return with p->lock held. // and return with p->lock held.
// Otherwise return 0. // Otherwise return 0.
static struct proc* static struct proc*
@ -95,18 +94,17 @@ allocproc(void)
return 0; return 0;
found: found:
p->state = EMBRYO;
p->pid = allocpid(); p->pid = allocpid();
// Allocate a page for the kernel stack. // Allocate a page for the kernel stack.
if((p->kstack = kalloc()) == 0){ if((p->kstack = kalloc()) == 0){
p->state = UNUSED;
return 0; return 0;
} }
// Allocate a trapframe page. // Allocate a trapframe page.
if((p->tf = (struct trapframe *)kalloc()) == 0){ if((p->tf = (struct trapframe *)kalloc()) == 0){
p->state = UNUSED; kfree(p->kstack);
p->kstack = 0;
return 0; return 0;
} }
@ -208,7 +206,7 @@ userinit(void)
uvminit(p->pagetable, initcode, sizeof(initcode)); uvminit(p->pagetable, initcode, sizeof(initcode));
p->sz = PGSIZE; p->sz = PGSIZE;
// prepare for the very first kernel->user. // prepare for the very first "return" from kernel to user.
p->tf->epc = 0; p->tf->epc = 0;
p->tf->sp = PGSIZE; p->tf->sp = PGSIZE;
@ -336,11 +334,10 @@ exit(void)
} }
} }
struct inode *cwd = p->cwd;
begin_op(); begin_op();
iput(cwd); iput(p->cwd);
end_op(); end_op();
p->cwd = 0;
acquire(&p->parent->lock); acquire(&p->parent->lock);
@ -348,7 +345,6 @@ exit(void)
reparent(p, p->parent); reparent(p, p->parent);
p->cwd = 0;
p->state = ZOMBIE; p->state = ZOMBIE;
// Parent might be sleeping in wait(). // Parent might be sleeping in wait().
@ -627,7 +623,6 @@ procdump(void)
{ {
static char *states[] = { static char *states[] = {
[UNUSED] "unused", [UNUSED] "unused",
[EMBRYO] "embryo",
[SLEEPING] "sleep ", [SLEEPING] "sleep ",
[RUNNABLE] "runble", [RUNNABLE] "runble",
[RUNNING] "run ", [RUNNING] "run ",

View file

@ -78,7 +78,7 @@ struct trapframe {
/* 280 */ uint64 t6; /* 280 */ uint64 t6;
}; };
enum procstate { UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE }; enum procstate { UNUSED, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
// Per-process state // Per-process state
struct proc { struct proc {