diff options
Diffstat (limited to 'lib/util')
-rw-r--r-- | lib/util/mempool.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/util/mempool.c b/lib/util/mempool.c index 9b2d905..5191fa2 100644 --- a/lib/util/mempool.c +++ b/lib/util/mempool.c @@ -142,7 +142,7 @@ void *mem_pool_allocate(mem_pool_t *mem) size_t idx, i, j; void *ptr = NULL; pool_t *it; - +retry_pool: for (it = mem->pool_list; it != NULL; it = it->next) { if (it->obj_free > 0) break; @@ -162,11 +162,21 @@ void *mem_pool_allocate(mem_pool_t *mem) break; } + if (i == mem->bitmap_count) { + it->obj_free = 0; + goto retry_pool; + } + for (j = 0; j < (sizeof(it->bitmap[i]) * CHAR_BIT); ++j) { if (!(it->bitmap[i] & (1UL << j))) break; } + if (j == (sizeof(it->bitmap[i]) * CHAR_BIT)) { + it->obj_free = 0; + goto retry_pool; + } + idx = i * sizeof(unsigned int) * CHAR_BIT + j; ptr = it->data + idx * mem->obj_size; |