summaryrefslogtreecommitdiff
path: root/kernel/trap.c
diff options
context:
space:
mode:
authorFrans Kaashoek <[email protected]>2022-08-10 20:35:42 -0400
committerFrans Kaashoek <[email protected]>2022-08-10 20:35:42 -0400
commit4087a6e7fc773ba4eb217dfc196dfe1eee84b25d (patch)
treea77a5b04944ed3f83ea10875aa32b1322e4224c6 /kernel/trap.c
parentb1fd09335ae1c112a01cedad0a6abd584fe8dca7 (diff)
downloadxv6-labs-4087a6e7fc773ba4eb217dfc196dfe1eee84b25d.tar.gz
xv6-labs-4087a6e7fc773ba4eb217dfc196dfe1eee84b25d.tar.bz2
xv6-labs-4087a6e7fc773ba4eb217dfc196dfe1eee84b25d.zip
Read and write p->killed using atomics
Diffstat (limited to 'kernel/trap.c')
-rw-r--r--kernel/trap.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/kernel/trap.c b/kernel/trap.c
index 75fb3ec..b879f01 100644
--- a/kernel/trap.c
+++ b/kernel/trap.c
@@ -53,7 +53,7 @@ usertrap(void)
if(r_scause() == 8){
// system call
- if(p->killed)
+ if(__sync_add_and_fetch(&p->killed, 0))
exit(-1);
// sepc points to the ecall instruction,
@@ -70,10 +70,10 @@ 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());
- 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);
// give up the CPU if this is a timer interrupt.