From 9583b476bf0caa3fca61f08dcb8afe138f4b4fb9 Mon Sep 17 00:00:00 2001 From: rsc Date: Thu, 9 Aug 2007 17:32:40 +0000 Subject: [PATCH] try to use cp only for curproc[cpu()] --- proc.c | 18 +++++++++--------- syscall.c | 18 +++++++++--------- sysfile.c | 23 ++++++++++++----------- umalloc.c | 14 +++++++------- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/proc.c b/proc.c index 37adbb4..89eb1d4 100644 --- a/proc.c +++ b/proc.c @@ -204,9 +204,9 @@ scheduler(void) void sched(void) { - struct proc *p = curproc[cpu()]; + struct proc *cp = curproc[cpu()]; - if(p->state == RUNNING) + if(cp->state == RUNNING) panic("sched running"); if(!holding(&proc_table_lock)) panic("sched proc_table_lock"); @@ -221,10 +221,10 @@ sched(void) void yield(void) { - struct proc *p = curproc[cpu()]; + struct proc *cp = curproc[cpu()]; acquire(&proc_table_lock); - p->state = RUNNABLE; + cp->state = RUNNABLE; sched(); release(&proc_table_lock); } @@ -246,9 +246,9 @@ forkret(void) void sleep(void *chan, struct spinlock *lk) { - struct proc *p = curproc[cpu()]; + struct proc *cp = curproc[cpu()]; - if(p == 0) + if(cp == 0) panic("sleep"); if(lk == 0) @@ -266,12 +266,12 @@ sleep(void *chan, struct spinlock *lk) } // Go to sleep. - p->chan = chan; - p->state = SLEEPING; + cp->chan = chan; + cp->state = SLEEPING; sched(); // Tidy up. - p->chan = 0; + cp->chan = 0; // Reacquire original lock. if(lk != &proc_table_lock){ diff --git a/syscall.c b/syscall.c index b44a7a9..adc2b58 100644 --- a/syscall.c +++ b/syscall.c @@ -37,15 +37,15 @@ fetchint(struct proc *p, uint addr, int *ip) int fetchstr(struct proc *p, uint addr, char **pp) { - char *cp, *ep; + char *s, *ep; if(addr >= p->sz) return -1; *pp = p->mem + addr; ep = p->mem + p->sz; - for(cp = *pp; cp < ep; cp++) - if(*cp == 0) - return cp - *pp; + for(s = *pp; s < ep; s++) + if(*s == 0) + return s - *pp; return -1; } @@ -53,9 +53,9 @@ fetchstr(struct proc *p, uint addr, char **pp) int argint(int argno, int *ip) { - struct proc *p = curproc[cpu()]; + struct proc *cp = curproc[cpu()]; - return fetchint(p, p->tf->esp + 4 + 4*argno, ip); + return fetchint(cp, cp->tf->esp + 4 + 4*argno, ip); } // Fetch the nth word-sized system call argument as a pointer @@ -65,13 +65,13 @@ int argptr(int argno, char **pp, int size) { int i; - struct proc *p = curproc[cpu()]; + struct proc *cp = curproc[cpu()]; if(argint(argno, &i) < 0) return -1; - if((uint)i >= p->sz || (uint)i+size >= p->sz) + if((uint)i >= cp->sz || (uint)i+size >= cp->sz) return -1; - *pp = p->mem + i; + *pp = cp->mem + i; return 0; } diff --git a/sysfile.c b/sysfile.c index 475c907..b5d2337 100644 --- a/sysfile.c +++ b/sysfile.c @@ -22,11 +22,11 @@ argfd(int argno, int *pfd, struct file **pf) { int fd; struct file *f; - struct proc *p = curproc[cpu()]; + struct proc *cp = curproc[cpu()]; if(argint(argno, &fd) < 0) return -1; - if(fd < 0 || fd >= NOFILE || (f=p->ofile[fd]) == 0) + if(fd < 0 || fd >= NOFILE || (f=cp->ofile[fd]) == 0) return -1; if(pfd) *pfd = fd; @@ -41,10 +41,11 @@ static int fdalloc(struct file *f) { int fd; - struct proc *p = curproc[cpu()]; + struct proc *cp = curproc[cpu()]; + for(fd = 0; fd < NOFILE; fd++){ - if(p->ofile[fd] == 0){ - p->ofile[fd] = f; + if(cp->ofile[fd] == 0){ + cp->ofile[fd] = f; return fd; } } @@ -57,7 +58,7 @@ sys_pipe(void) int *fd; struct file *rf = 0, *wf = 0; int fd0, fd1; - struct proc *p = curproc[cpu()]; + struct proc *cp = curproc[cpu()]; if(argptr(0, (void*)&fd, 2*sizeof fd[0]) < 0) return -1; @@ -66,7 +67,7 @@ sys_pipe(void) fd0 = -1; if((fd0 = fdalloc(rf)) < 0 || (fd1 = fdalloc(wf)) < 0){ if(fd0 >= 0) - p->ofile[fd0] = 0; + cp->ofile[fd0] = 0; fileclose(rf); fileclose(wf); return -1; @@ -241,7 +242,7 @@ sys_mkdir(void) int sys_chdir(void) { - struct proc *p = curproc[cpu()]; + struct proc *cp = curproc[cpu()]; struct inode *ip; char *path; @@ -261,9 +262,9 @@ sys_chdir(void) return -1; } - idecref(p->cwd); - p->cwd = ip; - iunlock(p->cwd); + idecref(cp->cwd); + cp->cwd = ip; + iunlock(cp->cwd); return 0; } diff --git a/umalloc.c b/umalloc.c index 5128c32..3473c79 100644 --- a/umalloc.c +++ b/umalloc.c @@ -46,17 +46,17 @@ free(void *ap) static Header* morecore(uint nu) { - char *cp; - Header *up; + char *p; + Header *hp; if(nu < PAGE) nu = PAGE; - cp = sbrk(nu * sizeof(Header)); - if(cp == (char*) -1) + p = sbrk(nu * sizeof(Header)); + if(p == (char*) -1) return 0; - up = (Header*) cp; - up->s.size = nu; - free((void*)(up + 1)); + hp = (Header*)p; + hp->s.size = nu; + free((void*)(hp + 1)); return freep; }