static int canflush(Proc *p, Segment *s) { int i; Proc *ep; lock(&s->ref.lk); if(s->ref.ref == 1) { /* Easy if we are the only user */ s->ref.ref++; unlock(&s->ref.lk); return canpage(p); } s->ref.ref++; unlock(&s->ref.lk); /* Now we must do hardwork to ensure all processes which have tlb * entries for this segment will be flushed if we succeed in paging it out */ p = proctab(0); ep = &p[conf.nproc]; while(p < ep) { if(p->state != Dead) { for(i = 0; i < NSEG; i++) if(p->seg[i] == s) if(!canpage(p)) return 0; } p++; } return 1; }
static int canflush(Proc *p, Segment *s) { int i, x; lock(s); if(s->ref == 1) { /* Easy if we are the only user */ s->ref++; unlock(s); return canpage(p); } s->ref++; unlock(s); /* Now we must do hardwork to ensure all processes which have tlb * entries for this segment will be flushed if we succeed in paging it out */ for(x = 0; (p = psincref(x)) != nil; x++){ if(p->state != Dead) { for(i = 0; i < NSEG; i++){ if(p->seg[i] == s && !canpage(p)){ psdecref(p); return 0; } } } psdecref(p); } return 1; }