X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Futil%2Fslab.c;h=62634034fdc6ef0b1994d4d3d0e1233bf4f71b8b;hb=a7ecf78b900c28aafdc1cd1e1a4117feb30a66c9;hp=4264814cabc926c623f47b5b1a9b70f5578f3664;hpb=965ebc8b286afee827b820479cc1714a2aeb46cc;p=mesa.git diff --git a/src/util/slab.c b/src/util/slab.c index 4264814cabc..62634034fdc 100644 --- a/src/util/slab.c +++ b/src/util/slab.c @@ -28,12 +28,10 @@ #include #include -#define ALIGN(value, align) (((value) + (align) - 1) & ~((align) - 1)) - #define SLAB_MAGIC_ALLOCATED 0xcafe4321 #define SLAB_MAGIC_FREE 0x7ee01234 -#ifdef DEBUG +#ifndef NDEBUG #define SET_MAGIC(element, value) (element)->magic = (value) #define CHECK_MAGIC(element, value) assert((element)->magic == (value)) #else @@ -53,7 +51,7 @@ struct slab_element_header { */ intptr_t owner; -#ifdef DEBUG +#ifndef NDEBUG intptr_t magic; #endif }; @@ -109,8 +107,8 @@ slab_create_parent(struct slab_parent_pool *parent, unsigned num_items) { mtx_init(&parent->mutex, mtx_plain); - parent->element_size = ALIGN(sizeof(struct slab_element_header) + item_size, - sizeof(intptr_t)); + parent->element_size = ALIGN_POT(sizeof(struct slab_element_header) + item_size, + sizeof(intptr_t)); parent->num_elements = num_items; } @@ -140,6 +138,9 @@ void slab_create_child(struct slab_child_pool *pool, */ void slab_destroy_child(struct slab_child_pool *pool) { + if (!pool->parent) + return; /* the slab probably wasn't even created */ + mtx_lock(&pool->parent->mutex); while (pool->pages) { @@ -279,25 +280,25 @@ void slab_free(struct slab_child_pool *pool, void *ptr) * Allocate an object from the slab. Single-threaded (no mutex). */ void * -slab_alloc_st(struct slab_mempool *pool) +slab_alloc_st(struct slab_mempool *mempool) { - return slab_alloc(&pool->child); + return slab_alloc(&mempool->child); } /** * Free an object allocated from the slab. Single-threaded (no mutex). */ void -slab_free_st(struct slab_mempool *pool, void *ptr) +slab_free_st(struct slab_mempool *mempool, void *ptr) { - slab_free(&pool->child, ptr); + slab_free(&mempool->child, ptr); } void -slab_destroy(struct slab_mempool *pool) +slab_destroy(struct slab_mempool *mempool) { - slab_destroy_child(&pool->child); - slab_destroy_parent(&pool->parent); + slab_destroy_child(&mempool->child); + slab_destroy_parent(&mempool->parent); } /** @@ -307,10 +308,10 @@ slab_destroy(struct slab_mempool *pool) * \param num_items Number of objects to allocate at once. */ void -slab_create(struct slab_mempool *pool, +slab_create(struct slab_mempool *mempool, unsigned item_size, unsigned num_items) { - slab_create_parent(&pool->parent, item_size, num_items); - slab_create_child(&pool->child, &pool->parent); + slab_create_parent(&mempool->parent, item_size, num_items); + slab_create_child(&mempool->child, &mempool->parent); }