static int deccnt(Ref *r) { int x; x = _xdec(&r->ref); if(x < 0) panic("deccnt pc=%#p", getcallerpc(&r)); return x; }
void freeb(Block *b) { void *dead = (void*)Bdead; long ref; if(b == nil) return; if(Bmagic && b->magic != Bmagic) panic("freeb: bad magic %#lux in Block %#p; caller pc %#p", b->magic, b, getcallerpc(&b)); if((ref = _xdec(&b->ref)) > 0) return; if(ref < 0){ dumpstack(); panic("freeb: ref %ld; caller pc %#p", ref, getcallerpc(&b)); } /* * drivers which perform non cache coherent DMA manage their own buffer * pool of uncached buffers and provide their own free routine. */ if(b->free) { b->free(b); return; } if(b->flag & BINTR) { ilock(&ialloc); ialloc.bytes -= b->lim - b->base; iunlock(&ialloc); } /* poison the block in case someone is still holding onto it */ b->next = dead; b->rp = dead; b->wp = dead; b->lim = dead; b->base = dead; b->magic = 0; free(b); }