Clean up using killed()
This commit is contained in:
parent
4087a6e7fc
commit
975f3b31d3
|
@ -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(__sync_add_and_fetch(&(myproc()->killed), 0)){
|
||||
if(killed(myproc())){
|
||||
release(&cons.lock);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -90,6 +90,7 @@ void proc_mapstacks(pagetable_t);
|
|||
pagetable_t proc_pagetable(struct proc *);
|
||||
void proc_freepagetable(pagetable_t, uint64);
|
||||
int kill(int);
|
||||
int killed(struct proc*);
|
||||
struct cpu* mycpu(void);
|
||||
struct cpu* getmycpu(void);
|
||||
struct proc* myproc();
|
||||
|
|
|
@ -81,7 +81,7 @@ pipewrite(struct pipe *pi, uint64 addr, int n)
|
|||
|
||||
acquire(&pi->lock);
|
||||
while(i < n){
|
||||
if(pi->readopen == 0 || __sync_add_and_fetch(&pr->killed,0)){
|
||||
if(pi->readopen == 0 || killed(pr)){
|
||||
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(__sync_add_and_fetch(&pr->killed,0)){
|
||||
if(killed(pr)){
|
||||
release(&pi->lock);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -422,7 +422,7 @@ wait(uint64 addr)
|
|||
}
|
||||
|
||||
// No point waiting if we don't have any children.
|
||||
if(!havekids || __sync_add_and_fetch(&p->killed, 0)){
|
||||
if(!havekids || killed(p)){
|
||||
release(&wait_lock);
|
||||
return -1;
|
||||
}
|
||||
|
@ -601,6 +601,12 @@ kill(int pid)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
killed(struct proc *p)
|
||||
{
|
||||
return __sync_add_and_fetch(&p->killed, 0);
|
||||
}
|
||||
|
||||
// Copy to either a user address, or kernel address,
|
||||
// depending on usr_dst.
|
||||
// Returns 0 on success, -1 on error.
|
||||
|
|
|
@ -63,7 +63,7 @@ sys_sleep(void)
|
|||
acquire(&tickslock);
|
||||
ticks0 = ticks;
|
||||
while(ticks - ticks0 < n){
|
||||
if(__sync_add_and_fetch(&(myproc()->killed), 0)){
|
||||
if(killed(myproc())){
|
||||
release(&tickslock);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ usertrap(void)
|
|||
if(r_scause() == 8){
|
||||
// system call
|
||||
|
||||
if(__sync_add_and_fetch(&p->killed, 0))
|
||||
if(killed(p))
|
||||
exit(-1);
|
||||
|
||||
// sepc points to the ecall instruction,
|
||||
|
@ -73,7 +73,7 @@ usertrap(void)
|
|||
__sync_bool_compare_and_swap(&p->killed, 0, 1);
|
||||
}
|
||||
|
||||
if(__sync_add_and_fetch(&p->killed, 0))
|
||||
if(killed(p))
|
||||
exit(-1);
|
||||
|
||||
// give up the CPU if this is a timer interrupt.
|
||||
|
|
Loading…
Reference in a new issue