Read and write p->killed using atomics
This commit is contained in:
parent
b1fd09335a
commit
4087a6e7fc
|
@ -89,7 +89,7 @@ consoleread(int user_dst, uint64 dst, int n)
|
||||||
// wait until interrupt handler has put some
|
// wait until interrupt handler has put some
|
||||||
// input into cons.buffer.
|
// input into cons.buffer.
|
||||||
while(cons.r == cons.w){
|
while(cons.r == cons.w){
|
||||||
if(myproc()->killed){
|
if(__sync_add_and_fetch(&(myproc()->killed), 0)){
|
||||||
release(&cons.lock);
|
release(&cons.lock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ pipewrite(struct pipe *pi, uint64 addr, int n)
|
||||||
|
|
||||||
acquire(&pi->lock);
|
acquire(&pi->lock);
|
||||||
while(i < n){
|
while(i < n){
|
||||||
if(pi->readopen == 0 || pr->killed){
|
if(pi->readopen == 0 || __sync_add_and_fetch(&pr->killed,0)){
|
||||||
release(&pi->lock);
|
release(&pi->lock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ piperead(struct pipe *pi, uint64 addr, int n)
|
||||||
|
|
||||||
acquire(&pi->lock);
|
acquire(&pi->lock);
|
||||||
while(pi->nread == pi->nwrite && pi->writeopen){ //DOC: pipe-empty
|
while(pi->nread == pi->nwrite && pi->writeopen){ //DOC: pipe-empty
|
||||||
if(pr->killed){
|
if(__sync_add_and_fetch(&pr->killed,0)){
|
||||||
release(&pi->lock);
|
release(&pi->lock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -422,7 +422,7 @@ wait(uint64 addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// No point waiting if we don't have any children.
|
// No point waiting if we don't have any children.
|
||||||
if(!havekids || p->killed){
|
if(!havekids || __sync_add_and_fetch(&p->killed, 0)){
|
||||||
release(&wait_lock);
|
release(&wait_lock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -588,7 +588,7 @@ kill(int pid)
|
||||||
for(p = proc; p < &proc[NPROC]; p++){
|
for(p = proc; p < &proc[NPROC]; p++){
|
||||||
acquire(&p->lock);
|
acquire(&p->lock);
|
||||||
if(p->pid == pid){
|
if(p->pid == pid){
|
||||||
p->killed = 1;
|
__sync_bool_compare_and_swap(&p->killed, 0, 1);
|
||||||
if(p->state == SLEEPING){
|
if(p->state == SLEEPING){
|
||||||
// Wake process from sleep().
|
// Wake process from sleep().
|
||||||
p->state = RUNNABLE;
|
p->state = RUNNABLE;
|
||||||
|
|
|
@ -63,7 +63,7 @@ sys_sleep(void)
|
||||||
acquire(&tickslock);
|
acquire(&tickslock);
|
||||||
ticks0 = ticks;
|
ticks0 = ticks;
|
||||||
while(ticks - ticks0 < n){
|
while(ticks - ticks0 < n){
|
||||||
if(myproc()->killed){
|
if(__sync_add_and_fetch(&(myproc()->killed), 0)){
|
||||||
release(&tickslock);
|
release(&tickslock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ usertrap(void)
|
||||||
if(r_scause() == 8){
|
if(r_scause() == 8){
|
||||||
// system call
|
// system call
|
||||||
|
|
||||||
if(p->killed)
|
if(__sync_add_and_fetch(&p->killed, 0))
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
|
||||||
// sepc points to the ecall instruction,
|
// sepc points to the ecall instruction,
|
||||||
|
@ -70,10 +70,10 @@ usertrap(void)
|
||||||
} else {
|
} else {
|
||||||
printf("usertrap(): unexpected scause %p pid=%d\n", r_scause(), p->pid);
|
printf("usertrap(): unexpected scause %p pid=%d\n", r_scause(), p->pid);
|
||||||
printf(" sepc=%p stval=%p\n", r_sepc(), r_stval());
|
printf(" sepc=%p stval=%p\n", r_sepc(), r_stval());
|
||||||
p->killed = 1;
|
__sync_bool_compare_and_swap(&p->killed, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(p->killed)
|
if(__sync_add_and_fetch(&p->killed, 0))
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
|
||||||
// give up the CPU if this is a timer interrupt.
|
// give up the CPU if this is a timer interrupt.
|
||||||
|
|
Loading…
Reference in a new issue