diff options
author | Frans Kaashoek <[email protected]> | 2017-01-31 20:21:14 -0500 |
---|---|---|
committer | Frans Kaashoek <[email protected]> | 2017-01-31 20:21:14 -0500 |
commit | fbb4c0944422f860484142010bb9f366f3e87bf8 (patch) | |
tree | 5e339842d43d09a4d23f1a2165391f00af30e308 /sysfile.c | |
parent | abf847a083888bbed4260ecacf849ea19f23e810 (diff) | |
download | xv6-labs-fbb4c0944422f860484142010bb9f366f3e87bf8.tar.gz xv6-labs-fbb4c0944422f860484142010bb9f366f3e87bf8.tar.bz2 xv6-labs-fbb4c0944422f860484142010bb9f366f3e87bf8.zip |
Read curproc from cpu structure, but be careful because after a schedule event
myproc() points to a different thread.
myproc();
sched();
myproc(); // this proc maybe different than the one before sched
Thus, in a function that operates on one thread better to retrieve the
current process once at the start of the function.
Diffstat (limited to 'sysfile.c')
-rw-r--r-- | sysfile.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -41,10 +41,11 @@ static int fdalloc(struct file *f) { int fd; + struct proc *curproc = myproc(); for(fd = 0; fd < NOFILE; fd++){ - if(myproc()->ofile[fd] == 0){ - myproc()->ofile[fd] = f; + if(curproc->ofile[fd] == 0){ + curproc->ofile[fd] = f; return fd; } } @@ -373,7 +374,8 @@ sys_chdir(void) { char *path; struct inode *ip; - + struct proc *curproc = myproc(); + begin_op(); if(argstr(0, &path) < 0 || (ip = namei(path)) == 0){ end_op(); @@ -386,9 +388,9 @@ sys_chdir(void) return -1; } iunlock(ip); - iput(myproc()->cwd); + iput(curproc->cwd); end_op(); - myproc()->cwd = ip; + curproc->cwd = ip; return 0; } |