void * tfw_pool_alloc(TfwPool *p, size_t n) { void *a; n = TFW_POOL_ALIGN_SZ(n); if (unlikely(p->off + n > TFW_POOL_CHUNK_SZ(p))) { TfwPoolChunk *c, *curr = p->curr; unsigned int off = TFW_POOL_ALIGN_SZ(sizeof(TfwPoolChunk)) + n; unsigned int order = get_order(off); c = (TfwPoolChunk *)tfw_pool_alloc_pages(order); if (!c) return NULL; c->next = curr; c->order = order; curr->off = p->off; p->order = order; p->off = off; p->curr = c; return (void *)TFW_POOL_ALIGN_SZ((unsigned long)(c + 1)); } a = (char *)TFW_POOL_CHUNK_END(p); p->off += n; return a; }
/** * Allocate bit more pages than we need. */ TfwPool * __tfw_pool_new(size_t n) { TfwPool *p; TfwPoolChunk *c; unsigned int order; order = get_order(TFW_POOL_ALIGN_SZ(n) + TFW_POOL_HEAD_OFF); c = (TfwPoolChunk *)tfw_pool_alloc_pages(order); if (unlikely(!c)) return NULL; p = (TfwPool *)((char *)c + TFW_POOL_ALIGN_SZ(sizeof(*c))); c->next = NULL; p->order = c->order = order; p->off = c->off = TFW_POOL_HEAD_OFF; p->curr = c; return p; }
TfwPool * __tfw_pool_new(size_t n) { TfwPool *p; TfwPoolChunk *c; unsigned int order; order = get_order(TFW_POOL_ALIGN_SZ(n) + TFW_POOL_HEAD_OFF); p = (TfwPool *)tfw_pool_alloc_pages(order); if (!p) return NULL; c = tfw_pool_chunk_first(p); c->next = NULL; c->order = order; c->off = TFW_POOL_ALIGN_SZ((char *)(c + 1) - (char *)p); p->curr = c; return p; }