Use atomic store_n and load_n

This commit is contained in:
Frans Kaashoek 2022-08-11 08:42:52 -04:00
parent 975f3b31d3
commit 429c7b717e
2 changed files with 3 additions and 3 deletions

View file

@ -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){
__sync_bool_compare_and_swap(&p->killed, 0, 1); __atomic_store_n(&p->killed, 1, __ATOMIC_SEQ_CST);
if(p->state == SLEEPING){ if(p->state == SLEEPING){
// Wake process from sleep(). // Wake process from sleep().
p->state = RUNNABLE; p->state = RUNNABLE;
@ -604,7 +604,7 @@ kill(int pid)
int int
killed(struct proc *p) killed(struct proc *p)
{ {
return __sync_add_and_fetch(&p->killed, 0); return __atomic_load_n(&p->killed, __ATOMIC_SEQ_CST);
} }
// Copy to either a user address, or kernel address, // Copy to either a user address, or kernel address,

View file

@ -70,7 +70,7 @@ 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());
__sync_bool_compare_and_swap(&p->killed, 0, 1); __atomic_store_n(&p->killed, 1, __ATOMIC_SEQ_CST);
} }
if(killed(p)) if(killed(p))