Lines Matching refs:pool

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