Skip to content

Commit

Permalink
try to use cp only for curproc[cpu()]
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Aug 9, 2007
1 parent 2233065 commit 9583b47
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 36 deletions.
18 changes: 9 additions & 9 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
}
Expand All @@ -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)
Expand All @@ -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){
Expand Down
18 changes: 9 additions & 9 deletions syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,25 @@ 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;
}

// Fetch the argno'th word-sized system call argument as an integer.
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
Expand All @@ -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;
}

Expand Down
23 changes: 12 additions & 11 deletions sysfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down
14 changes: 7 additions & 7 deletions umalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 9583b47

Please sign in to comment.