diff options
author | Marek Olšák <maraeo@gmail.com> | 2010-11-29 23:37:25 +0100 |
---|---|---|
committer | Marek Olšák <maraeo@gmail.com> | 2010-11-30 10:12:26 +0100 |
commit | 80f24c1575688e9cd4a5a811137f43b7e0a661bb (patch) | |
tree | cc76bc3861f325d9f4bf372eeee7ff328541e5e7 /src/gallium/auxiliary | |
parent | 557280542399629ac64a48f5b618365e2b18fce1 (diff) |
util: rename u_mempool -> u_slab
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/Makefile | 2 | ||||
-rw-r--r-- | src/gallium/auxiliary/SConscript | 2 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_slab.c (renamed from src/gallium/auxiliary/util/u_mempool.c) | 94 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_slab.h (renamed from src/gallium/auxiliary/util/u_mempool.h) | 50 |
4 files changed, 74 insertions, 74 deletions
diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index 53a0847f03..9aa5412178 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -128,12 +128,12 @@ C_SOURCES = \ util/u_linkage.c \ util/u_network.c \ util/u_math.c \ - util/u_mempool.c \ util/u_mm.c \ util/u_rect.c \ util/u_ringbuffer.c \ util/u_sampler.c \ util/u_simple_shaders.c \ + util/u_slab.c \ util/u_snprintf.c \ util/u_staging.c \ util/u_surface.c \ diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript index 75c27dd242..fca7e5fd11 100644 --- a/src/gallium/auxiliary/SConscript +++ b/src/gallium/auxiliary/SConscript @@ -175,13 +175,13 @@ source = [ 'util/u_linkage.c', 'util/u_network.c', 'util/u_math.c', - 'util/u_mempool.c', 'util/u_mm.c', 'util/u_rect.c', 'util/u_resource.c', 'util/u_ringbuffer.c', 'util/u_sampler.c', 'util/u_simple_shaders.c', + 'util/u_slab.c', 'util/u_snprintf.c', 'util/u_staging.c', 'util/u_surface.c', diff --git a/src/gallium/auxiliary/util/u_mempool.c b/src/gallium/auxiliary/util/u_slab.c index 1f336b39a1..21bf2d735a 100644 --- a/src/gallium/auxiliary/util/u_mempool.c +++ b/src/gallium/auxiliary/util/u_slab.c @@ -20,7 +20,7 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "util/u_mempool.h" +#include "util/u_slab.h" #include "util/u_math.h" #include "util/u_memory.h" @@ -28,13 +28,13 @@ #include <stdio.h> -#define UTIL_MEMPOOL_MAGIC 0xcafe4321 +#define UTIL_SLAB_MAGIC 0xcafe4321 /* The block is either allocated memory or free space. */ -struct util_mempool_block { +struct util_slab_block { /* The header. */ /* The first next free block. */ - struct util_mempool_block *next_free; + struct util_slab_block *next_free; intptr_t magic; @@ -42,19 +42,19 @@ struct util_mempool_block { * The allocated size is always larger than this structure. */ }; -static struct util_mempool_block * -util_mempool_get_block(struct util_mempool *pool, - struct util_mempool_page *page, unsigned index) +static struct util_slab_block * +util_slab_get_block(struct util_slab_mempool *pool, + struct util_slab_page *page, unsigned index) { - return (struct util_mempool_block*) - ((uint8_t*)page + sizeof(struct util_mempool_page) + + return (struct util_slab_block*) + ((uint8_t*)page + sizeof(struct util_slab_page) + (pool->block_size * index)); } -static void util_mempool_add_new_page(struct util_mempool *pool) +static void util_slab_add_new_page(struct util_slab_mempool *pool) { - struct util_mempool_page *page; - struct util_mempool_block *block; + struct util_slab_page *page; + struct util_slab_block *block; int i; page = MALLOC(pool->page_size); @@ -62,15 +62,15 @@ static void util_mempool_add_new_page(struct util_mempool *pool) /* Mark all blocks as free. */ for (i = 0; i < pool->num_blocks-1; i++) { - block = util_mempool_get_block(pool, page, i); - block->next_free = util_mempool_get_block(pool, page, i+1); - block->magic = UTIL_MEMPOOL_MAGIC; + block = util_slab_get_block(pool, page, i); + block->next_free = util_slab_get_block(pool, page, i+1); + block->magic = UTIL_SLAB_MAGIC; } - block = util_mempool_get_block(pool, page, pool->num_blocks-1); + block = util_slab_get_block(pool, page, pool->num_blocks-1); block->next_free = pool->first_free; - block->magic = UTIL_MEMPOOL_MAGIC; - pool->first_free = util_mempool_get_block(pool, page, 0); + block->magic = UTIL_SLAB_MAGIC; + pool->first_free = util_slab_get_block(pool, page, 0); pool->num_pages++; #if 0 @@ -78,74 +78,74 @@ static void util_mempool_add_new_page(struct util_mempool *pool) #endif } -static void *util_mempool_malloc_st(struct util_mempool *pool) +static void *util_slab_alloc_st(struct util_slab_mempool *pool) { - struct util_mempool_block *block; + struct util_slab_block *block; if (!pool->first_free) - util_mempool_add_new_page(pool); + util_slab_add_new_page(pool); block = pool->first_free; - assert(block->magic == UTIL_MEMPOOL_MAGIC); + assert(block->magic == UTIL_SLAB_MAGIC); pool->first_free = block->next_free; - return (uint8_t*)block + sizeof(struct util_mempool_block); + return (uint8_t*)block + sizeof(struct util_slab_block); } -static void util_mempool_free_st(struct util_mempool *pool, void *ptr) +static void util_slab_free_st(struct util_slab_mempool *pool, void *ptr) { - struct util_mempool_block *block = - (struct util_mempool_block*) - ((uint8_t*)ptr - sizeof(struct util_mempool_block)); + struct util_slab_block *block = + (struct util_slab_block*) + ((uint8_t*)ptr - sizeof(struct util_slab_block)); - assert(block->magic == UTIL_MEMPOOL_MAGIC); + assert(block->magic == UTIL_SLAB_MAGIC); block->next_free = pool->first_free; pool->first_free = block; } -static void *util_mempool_malloc_mt(struct util_mempool *pool) +static void *util_slab_alloc_mt(struct util_slab_mempool *pool) { void *mem; pipe_mutex_lock(pool->mutex); - mem = util_mempool_malloc_st(pool); + mem = util_slab_alloc_st(pool); pipe_mutex_unlock(pool->mutex); return mem; } -static void util_mempool_free_mt(struct util_mempool *pool, void *ptr) +static void util_slab_free_mt(struct util_slab_mempool *pool, void *ptr) { pipe_mutex_lock(pool->mutex); - util_mempool_free_st(pool, ptr); + util_slab_free_st(pool, ptr); pipe_mutex_unlock(pool->mutex); } -void util_mempool_set_thread_safety(struct util_mempool *pool, - enum util_mempool_threading threading) +void util_slab_set_thread_safety(struct util_slab_mempool *pool, + enum util_slab_threading threading) { pool->threading = threading; if (threading) { - pool->malloc = util_mempool_malloc_mt; - pool->free = util_mempool_free_mt; + pool->alloc = util_slab_alloc_mt; + pool->free = util_slab_free_mt; } else { - pool->malloc = util_mempool_malloc_st; - pool->free = util_mempool_free_st; + pool->alloc = util_slab_alloc_st; + pool->free = util_slab_free_st; } } -void util_mempool_create(struct util_mempool *pool, - unsigned item_size, - unsigned num_blocks, - enum util_mempool_threading threading) +void util_slab_create(struct util_slab_mempool *pool, + unsigned item_size, + unsigned num_blocks, + enum util_slab_threading threading) { item_size = align(item_size, sizeof(intptr_t)); pool->num_pages = 0; pool->num_blocks = num_blocks; - pool->block_size = sizeof(struct util_mempool_block) + item_size; + pool->block_size = sizeof(struct util_slab_block) + item_size; pool->block_size = align(pool->block_size, sizeof(intptr_t)); - pool->page_size = sizeof(struct util_mempool_page) + + pool->page_size = sizeof(struct util_slab_page) + num_blocks * pool->block_size; pool->first_free = NULL; @@ -153,12 +153,12 @@ void util_mempool_create(struct util_mempool *pool, pipe_mutex_init(pool->mutex); - util_mempool_set_thread_safety(pool, threading); + util_slab_set_thread_safety(pool, threading); } -void util_mempool_destroy(struct util_mempool *pool) +void util_slab_destroy(struct util_slab_mempool *pool) { - struct util_mempool_page *page, *temp; + struct util_slab_page *page, *temp; foreach_s(page, temp, &pool->list) { remove_from_list(page); diff --git a/src/gallium/auxiliary/util/u_mempool.h b/src/gallium/auxiliary/util/u_slab.h index a5b5d6a9b7..6b9718d08a 100644 --- a/src/gallium/auxiliary/util/u_mempool.h +++ b/src/gallium/auxiliary/util/u_slab.h @@ -22,66 +22,66 @@ /** * @file - * Simple memory pool for equally sized memory allocations. - * util_mempool_malloc and util_mempool_free are in O(1). + * Simple slab allocator for equally sized memory allocations. + * util_slab_alloc and util_slab_free have time complexity in O(1). * * Good for allocations which have very low lifetime and are allocated - * and freed very often. Use a profiler first! + * and freed very often. Use a profiler first to know if it's worth using it! * * Candidates: get_transfer, user_buffer_create * * @author Marek Olšák */ -#ifndef U_MEMPOOL_H -#define U_MEMPOOL_H +#ifndef U_SLAB_H +#define U_SLAB_H #include "os/os_thread.h" -enum util_mempool_threading { - UTIL_MEMPOOL_SINGLETHREADED = FALSE, - UTIL_MEMPOOL_MULTITHREADED = TRUE +enum util_slab_threading { + UTIL_SLAB_SINGLETHREADED = FALSE, + UTIL_SLAB_MULTITHREADED = TRUE }; /* The page is an array of blocks (allocations). */ -struct util_mempool_page { +struct util_slab_page { /* The header (linked-list pointers). */ - struct util_mempool_page *prev, *next; + struct util_slab_page *prev, *next; /* Memory after the last member is dedicated to the page itself. * The allocated size is always larger than this structure. */ }; -struct util_mempool { +struct util_slab_mempool { /* Public members. */ - void *(*malloc)(struct util_mempool *pool); - void (*free)(struct util_mempool *pool, void *ptr); + void *(*alloc)(struct util_slab_mempool *pool); + void (*free)(struct util_slab_mempool *pool, void *ptr); /* Private members. */ - struct util_mempool_block *first_free; + struct util_slab_block *first_free; - struct util_mempool_page list; + struct util_slab_page list; unsigned block_size; unsigned page_size; unsigned num_blocks; unsigned num_pages; - enum util_mempool_threading threading; + enum util_slab_threading threading; pipe_mutex mutex; }; -void util_mempool_create(struct util_mempool *pool, - unsigned item_size, - unsigned num_blocks, - enum util_mempool_threading threading); +void util_slab_create(struct util_slab_mempool *pool, + unsigned item_size, + unsigned num_blocks, + enum util_slab_threading threading); -void util_mempool_destroy(struct util_mempool *pool); +void util_slab_destroy(struct util_slab_mempool *pool); -void util_mempool_set_thread_safety(struct util_mempool *pool, - enum util_mempool_threading threading); +void util_slab_set_thread_safety(struct util_slab_mempool *pool, + enum util_slab_threading threading); -#define util_mempool_malloc(pool) (pool)->malloc(pool) -#define util_mempool_free(pool, ptr) (pool)->free(pool, ptr) +#define util_slab_alloc(pool) (pool)->alloc(pool) +#define util_slab_free(pool, ptr) (pool)->free(pool, ptr) #endif |