Lines Matching refs:pool
46 util_slab_get_block(struct util_slab_mempool *pool, in util_slab_get_block() argument
51 (pool->block_size * index)); in util_slab_get_block()
54 static void util_slab_add_new_page(struct util_slab_mempool *pool) in util_slab_add_new_page() argument
60 page = MALLOC(pool->page_size); in util_slab_add_new_page()
61 insert_at_tail(&pool->list, page); in util_slab_add_new_page()
64 for (i = 0; i < pool->num_blocks-1; i++) { in util_slab_add_new_page()
65 block = util_slab_get_block(pool, page, i); in util_slab_add_new_page()
66 block->next_free = util_slab_get_block(pool, page, i+1); in util_slab_add_new_page()
70 block = util_slab_get_block(pool, page, pool->num_blocks-1); in util_slab_add_new_page()
71 block->next_free = pool->first_free; in util_slab_add_new_page()
73 pool->first_free = util_slab_get_block(pool, page, 0); in util_slab_add_new_page()
74 pool->num_pages++; in util_slab_add_new_page()
77 fprintf(stderr, "New page! Num of pages: %i\n", pool->num_pages); in util_slab_add_new_page()
81 static void *util_slab_alloc_st(struct util_slab_mempool *pool) in util_slab_alloc_st() argument
85 if (!pool->first_free) in util_slab_alloc_st()
86 util_slab_add_new_page(pool); in util_slab_alloc_st()
88 block = pool->first_free; in util_slab_alloc_st()
90 pool->first_free = block->next_free; in util_slab_alloc_st()
95 static void util_slab_free_st(struct util_slab_mempool *pool, void *ptr) in util_slab_free_st() argument
102 block->next_free = pool->first_free; in util_slab_free_st()
103 pool->first_free = block; in util_slab_free_st()
106 static void *util_slab_alloc_mt(struct util_slab_mempool *pool) in util_slab_alloc_mt() argument
110 pipe_mutex_lock(pool->mutex); in util_slab_alloc_mt()
111 mem = util_slab_alloc_st(pool); in util_slab_alloc_mt()
112 pipe_mutex_unlock(pool->mutex); in util_slab_alloc_mt()
116 static void util_slab_free_mt(struct util_slab_mempool *pool, void *ptr) in util_slab_free_mt() argument
118 pipe_mutex_lock(pool->mutex); in util_slab_free_mt()
119 util_slab_free_st(pool, ptr); in util_slab_free_mt()
120 pipe_mutex_unlock(pool->mutex); in util_slab_free_mt()
123 void util_slab_set_thread_safety(struct util_slab_mempool *pool, in util_slab_set_thread_safety() argument
126 pool->threading = threading; in util_slab_set_thread_safety()
129 pool->alloc = util_slab_alloc_mt; in util_slab_set_thread_safety()
130 pool->free = util_slab_free_mt; in util_slab_set_thread_safety()
132 pool->alloc = util_slab_alloc_st; in util_slab_set_thread_safety()
133 pool->free = util_slab_free_st; in util_slab_set_thread_safety()
137 void util_slab_create(struct util_slab_mempool *pool, in util_slab_create() argument
144 pool->num_pages = 0; in util_slab_create()
145 pool->num_blocks = num_blocks; in util_slab_create()
146 pool->block_size = sizeof(struct util_slab_block) + item_size; in util_slab_create()
147 pool->block_size = align(pool->block_size, sizeof(intptr_t)); in util_slab_create()
148 pool->page_size = sizeof(struct util_slab_page) + in util_slab_create()
149 num_blocks * pool->block_size; in util_slab_create()
150 pool->first_free = NULL; in util_slab_create()
152 make_empty_list(&pool->list); in util_slab_create()
154 pipe_mutex_init(pool->mutex); in util_slab_create()
156 util_slab_set_thread_safety(pool, threading); in util_slab_create()
159 void util_slab_destroy(struct util_slab_mempool *pool) in util_slab_destroy() argument
163 if (pool->list.next) { in util_slab_destroy()
164 foreach_s(page, temp, &pool->list) { in util_slab_destroy()
170 pipe_mutex_destroy(pool->mutex); in util_slab_destroy()