Page * lookpage(Image *i, uint32_t daddr) { Page *f; lock(&pga.hashlock); for(f = pghash(daddr); f; f = f->hash){ if(f->image == i && f->daddr == daddr){ unlock(&pga.hashlock); lock(&pga.l); lock(&f->l); if(f->image != i || f->daddr != daddr){ unlock(&f->l); unlock(&pga.l); return 0; } if(++f->ref == 1) pageunchain(f); unlock(&pga.l); unlock(&f->l); return f; } } unlock(&pga.hashlock); return nil; }
Page * lookpage(Image *i, ulong daddr) { Page *f; lock(&palloc.hashlock); for(f = pghash(daddr); f; f = f->hash) { if(f->image == i && f->daddr == daddr) { unlock(&palloc.hashlock); lock(&palloc); lock(f); if(f->image != i || f->daddr != daddr) { unlock(f); unlock(&palloc); return 0; } if(++f->ref == 1) pageunchain(f); unlock(&palloc); unlock(f); return f; } } unlock(&palloc.hashlock); return 0; }
void cachepage(Page *p, Image *i) { Page **l; /* If this ever happens it should be fixed by calling * uncachepage instead of panic. I think there is a race * with pio in which this can happen. Calling uncachepage is * correct - I just wanted to see if we got here. */ if(p->image) panic("cachepage"); incref(&i->r); lock(&pga.hashlock); p->image = i; l = &pghash(p->daddr); p->hash = *l; *l = p; unlock(&pga.hashlock); }
void uncachepage(Page *p) /* Always called with a locked page */ { Page **l, *f; if(p->image == 0) return; lock(&pga.hashlock); l = &pghash(p->daddr); for(f = *l; f; f = f->hash){ if(f == p){ *l = p->hash; break; } l = &f->hash; } unlock(&pga.hashlock); putimage(p->image); p->image = 0; p->daddr = 0; }
void cachedel(Image *i, uint32_t daddr) { Page *f, **l; lock(&pga.hashlock); l = &pghash(daddr); for(f = *l; f; f = f->hash){ if(f->image == i && f->daddr == daddr){ lock(&f->l); if(f->image == i && f->daddr == daddr){ *l = f->hash; putimage(f->image); f->image = nil; f->daddr = 0; } unlock(&f->l); break; } l = &f->hash; } unlock(&pga.hashlock); }
void cachedel(Image *i, ulong daddr) { Page *f, **l; lock(&palloc.hashlock); l = &pghash(daddr); for(f = *l; f; f = f->hash) { if(f->image == i && f->daddr == daddr) { lock(f); if(f->image == i && f->daddr == daddr){ *l = f->hash; putimage(f->image); f->image = 0; f->daddr = 0; } unlock(f); break; } l = &f->hash; } unlock(&palloc.hashlock); }