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.
This commit is contained in:
parent
abf847a083
commit
fbb4c09444
7 changed files with 97 additions and 62 deletions
12
sysfile.c
12
sysfile.c
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue