summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/console.c2
-rw-r--r--kernel/pipe.c4
-rw-r--r--kernel/proc.c4
-rw-r--r--kernel/sysproc.c2
-rw-r--r--kernel/trap.c6
5 files changed, 9 insertions, 9 deletions
diff --git a/kernel/console.c b/kernel/console.c
index 23a2d35..b8fa1de 100644
--- a/kernel/console.c
+++ b/kernel/console.c
@@ -89,7 +89,7 @@ consoleread(int user_dst, uint64 dst, int n)
// wait until interrupt handler has put some
// input into cons.buffer.
while(cons.r == cons.w){
- if(myproc()->killed){
+ if(__sync_add_and_fetch(&(myproc()->killed), 0)){
release(&cons.lock);
return -1;
}
diff --git a/kernel/pipe.c b/kernel/pipe.c
index b6eefb9..e438d7e 100644
--- a/kernel/pipe.c
+++ b/kernel/pipe.c
@@ -81,7 +81,7 @@ pipewrite(struct pipe *pi, uint64 addr, int n)
acquire(&pi->lock);
while(i < n){
- if(pi->readopen == 0 || pr->killed){
+ if(pi->readopen == 0 || __sync_add_and_fetch(&pr->killed,0)){
release(&pi->lock);
return -1;
}
@@ -111,7 +111,7 @@ piperead(struct pipe *pi, uint64 addr, int n)
acquire(&pi->lock);
while(pi->nread == pi->nwrite && pi->writeopen){ //DOC: pipe-empty
- if(pr->killed){
+ if(__sync_add_and_fetch(&pr->killed,0)){
release(&pi->lock);
return -1;
}
diff --git a/kernel/proc.c b/kernel/proc.c
index 2d0ffa1..221f0f8 100644
--- a/kernel/proc.c
+++ b/kernel/proc.c
@@ -422,7 +422,7 @@ wait(uint64 addr)
}
// 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);
return -1;
}
@@ -588,7 +588,7 @@ kill(int pid)
for(p = proc; p < &proc[NPROC]; p++){
acquire(&p->lock);
if(p->pid == pid){
- p->killed = 1;
+ __sync_bool_compare_and_swap(&p->killed, 0, 1);
if(p->state == SLEEPING){
// Wake process from sleep().
p->state = RUNNABLE;
diff --git a/kernel/sysproc.c b/kernel/sysproc.c
index e8bcda9..61b715b 100644
--- a/kernel/sysproc.c
+++ b/kernel/sysproc.c
@@ -63,7 +63,7 @@ sys_sleep(void)
acquire(&tickslock);
ticks0 = ticks;
while(ticks - ticks0 < n){
- if(myproc()->killed){
+ if(__sync_add_and_fetch(&(myproc()->killed), 0)){
release(&tickslock);
return -1;
}
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.