void tfw_pool_destroy(TfwPool *p) { TfwPoolChunk *c, *next, *first = tfw_pool_chunk_first(p); for (c = p->curr; c != first; c = next) { next = c->next; tfw_pool_free_pages(TFW_POOL_CHUNK_BASE(c), c->order); } tfw_pool_free_pages((unsigned long)p, first->order); }
void tfw_pool_destroy(TfwPool *p) { TfwPoolChunk *c, *next; for (c = p->curr; c; c = next) { next = c->next; tfw_pool_free_pages(TFW_POOL_CHUNK_BASE(c), c->order); } }
void tfw_pool_free(TfwPool *p, void *ptr, size_t n) { TfwPoolChunk *c = p->curr; n = TFW_POOL_ALIGN_SZ(n); /* Stack-like usage is expected. */ if (likely((char *)ptr + n == (char *)TFW_POOL_CHUNK_END(c))) c->off -= n; /* Free empty chunk which doesn't contain the pool header. */ if (unlikely(c != tfw_pool_chunk_first(p) && c->off == TFW_POOL_ALIGN_SZ(sizeof(*c)))) { p->curr = c->next; tfw_pool_free_pages(TFW_POOL_CHUNK_BASE(c), c->order); } }
/** * It's good to call the function against just allocated chunk in stack-manner. * Consequent free calls can empty the whole pool but the first chunk with * the pool header. */ void tfw_pool_free(TfwPool *p, void *ptr, size_t n) { n = TFW_POOL_ALIGN_SZ(n); /* Stack-like usage is expected. */ if (unlikely((char *)ptr + n != (char *)TFW_POOL_CHUNK_END(p))) return; p->off -= n; /* Free empty chunk which doesn't contain the pool header. */ if (unlikely(p->off == TFW_POOL_ALIGN_SZ(sizeof(TfwPoolChunk)))) { TfwPoolChunk *next = p->curr->next; tfw_pool_free_pages(TFW_POOL_CHUNK_BASE(p->curr), p->order); p->curr = next; p->order = next->order; p->off = next->off; } }