Use p->lock to read p->killed
This commit is contained in:
parent
429c7b717e
commit
4f716c8550
|
@ -91,6 +91,7 @@ pagetable_t proc_pagetable(struct proc *);
|
|||
void proc_freepagetable(pagetable_t, uint64);
|
||||
int kill(int);
|
||||
int killed(struct proc*);
|
||||
void setkilled(struct proc*);
|
||||
struct cpu* mycpu(void);
|
||||
struct cpu* getmycpu(void);
|
||||
struct proc* myproc();
|
||||
|
|
|
@ -588,7 +588,7 @@ kill(int pid)
|
|||
for(p = proc; p < &proc[NPROC]; p++){
|
||||
acquire(&p->lock);
|
||||
if(p->pid == pid){
|
||||
__atomic_store_n(&p->killed, 1, __ATOMIC_SEQ_CST);
|
||||
p->killed = 1;
|
||||
if(p->state == SLEEPING){
|
||||
// Wake process from sleep().
|
||||
p->state = RUNNABLE;
|
||||
|
@ -601,10 +601,23 @@ kill(int pid)
|
|||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
setkilled(struct proc *p)
|
||||
{
|
||||
acquire(&p->lock);
|
||||
p->killed = 1;
|
||||
release(&p->lock);
|
||||
}
|
||||
|
||||
int
|
||||
killed(struct proc *p)
|
||||
{
|
||||
return __atomic_load_n(&p->killed, __ATOMIC_SEQ_CST);
|
||||
int k;
|
||||
|
||||
acquire(&p->lock);
|
||||
k = p->killed;
|
||||
release(&p->lock);
|
||||
return k;
|
||||
}
|
||||
|
||||
// Copy to either a user address, or kernel address,
|
||||
|
|
|
@ -70,7 +70,7 @@ usertrap(void)
|
|||
} else {
|
||||
printf("usertrap(): unexpected scause %p pid=%d\n", r_scause(), p->pid);
|
||||
printf(" sepc=%p stval=%p\n", r_sepc(), r_stval());
|
||||
__atomic_store_n(&p->killed, 1, __ATOMIC_SEQ_CST);
|
||||
setkilled(p);
|
||||
}
|
||||
|
||||
if(killed(p))
|
||||
|
|
Loading…
Reference in a new issue