summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2019-07-08 11:11:00 -0400
committerRobert Morris <[email protected]>2019-07-08 11:11:00 -0400
commit9d34838b4f7c859b753a32124002d7d845140b0a (patch)
tree920c07864e31bc48b215df3f6ac2ad10133ff3b3 /kernel
parentdb72f3108fb729d4a9bbcc7ed3979a08eeadd022 (diff)
downloadxv6-labs-9d34838b4f7c859b753a32124002d7d845140b0a.tar.gz
xv6-labs-9d34838b4f7c859b753a32124002d7d845140b0a.tar.bz2
xv6-labs-9d34838b4f7c859b753a32124002d7d845140b0a.zip
holding p->lock all the way through state=RUNNABLE means we don't need EMBRYO
Diffstat (limited to 'kernel')
-rw-r--r--kernel/proc.c17
-rw-r--r--kernel/proc.h2
2 files changed, 7 insertions, 12 deletions
diff --git a/kernel/proc.c b/kernel/proc.c
index ade12d9..a947f7f 100644
--- a/kernel/proc.c
+++ b/kernel/proc.c
@@ -75,8 +75,7 @@ allocpid() {
//PAGEBREAK: 32
// Look in the process table for an UNUSED proc.
-// If found, change state to EMBRYO, initialize
-// state required to run in the kernel,
+// If found, initialize state required to run in the kernel,
// and return with p->lock held.
// Otherwise return 0.
static struct proc*
@@ -95,18 +94,17 @@ allocproc(void)
return 0;
found:
- p->state = EMBRYO;
p->pid = allocpid();
// Allocate a page for the kernel stack.
if((p->kstack = kalloc()) == 0){
- p->state = UNUSED;
return 0;
}
// Allocate a trapframe page.
if((p->tf = (struct trapframe *)kalloc()) == 0){
- p->state = UNUSED;
+ kfree(p->kstack);
+ p->kstack = 0;
return 0;
}
@@ -208,7 +206,7 @@ userinit(void)
uvminit(p->pagetable, initcode, sizeof(initcode));
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->sp = PGSIZE;
@@ -336,11 +334,10 @@ exit(void)
}
}
- struct inode *cwd = p->cwd;
-
begin_op();
- iput(cwd);
+ iput(p->cwd);
end_op();
+ p->cwd = 0;
acquire(&p->parent->lock);
@@ -348,7 +345,6 @@ exit(void)
reparent(p, p->parent);
- p->cwd = 0;
p->state = ZOMBIE;
// Parent might be sleeping in wait().
@@ -627,7 +623,6 @@ procdump(void)
{
static char *states[] = {
[UNUSED] "unused",
- [EMBRYO] "embryo",
[SLEEPING] "sleep ",
[RUNNABLE] "runble",
[RUNNING] "run ",
diff --git a/kernel/proc.h b/kernel/proc.h
index 0fa61ff..687fdd1 100644
--- a/kernel/proc.h
+++ b/kernel/proc.h
@@ -78,7 +78,7 @@ struct trapframe {
/* 280 */ uint64 t6;
};
-enum procstate { UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
+enum procstate { UNUSED, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
// Per-process state
struct proc {