-static int resize_pool(struct pool *pool)
-{
-#ifdef ENABLE_RESIZE
- unsigned int new_size = pool->size << 1;
- struct mem_hdr *hdr, *last_hdr;
- void *ptr;
-
- if (new_size >= MAX_SIZE || resize_error)
- return 1;
-
- if (ftruncate(pool->fd, new_size) < 0)
- goto fail;
-
- ptr = mremap(pool->map, pool->size, new_size, 0);
- if (ptr == MAP_FAILED)
- goto fail;
-
- pool->map = ptr;
- hdr = pool;
- do {
- last_hdr = hdr;
- } while ((hdr = hdr_nxt(hdr)) != NULL);
-
- if (hdr_free(last_hdr)) {
- last_hdr->size = hdr_size(last_hdr) + new_size - pool_size;
- hdr_mark_free(last_hdr);
- } else {
- struct mem_hdr *nxt;
-
- nxt = (void *) last_hdr + hdr_size(last_hdr) + sizeof(*hdr);
- nxt->size = new_size - pool_size - sizeof(*hdr);
- hdr_mark_free(nxt);
- }
-
- pool_room += new_size - pool_size;
- pool_size = new_size;
- return 0;
-fail:
- perror("resize");
- resize_error = 1;
-#else
- return 1;
-#endif
-}
-