Commit 9570a245 9570a2451e0c378e55d53e4cccaf0fff1eb44f06 by Sergey Poznyakoff

* include/mailutils/opool.h (mu_opool_set_bucket_size)

(mu_opool_get_bucket_size): New protos.
* mailbox/opool.c (struct _mu_opool.bucket_size): New member.
(alloc_pool, copy_chars): Use opool->bucket_size to set bucket
size.
(mu_opool_create): Initialize bucket_size with the default
value.
(mu_opool_set_bucket_size,mu_opool_get_bucket_size): New
functions.
1 parent 28e9a0a0
2008-11-28 Sergey Poznyakoff <gray@gnu.org.ua>
* include/mailutils/opool.h (mu_opool_set_bucket_size)
(mu_opool_get_bucket_size): New protos.
* mailbox/opool.c (struct _mu_opool.bucket_size): New member.
(alloc_pool, copy_chars): Use opool->bucket_size to set bucket
size.
(mu_opool_create): Initialize bucket_size with the default
value.
(mu_opool_set_bucket_size,mu_opool_get_bucket_size): New
functions.
2008-11-27 Sergey Poznyakoff <gray@gnu.org.ua>
Add iterator support to opool.
......
......@@ -29,6 +29,8 @@
resulting pool (including mu_opool_create itself) will abort on
not enough memory condition, using mu_alloc_die. */
int mu_opool_create (mu_opool_t *pret, int memerr);
int mu_opool_set_bucket_size (mu_opool_t opool, size_t size);
int mu_opool_get_bucket_size (mu_opool_t opool, size_t *psize);
/* Clear all data from the pool, so next mu_opool_append* call will
begin a new object. */
......
......@@ -42,6 +42,7 @@ struct mu_opool_bucket
struct _mu_opool
{
int memerr;
size_t bucket_size;
size_t itr_count;
struct mu_opool_bucket *head, *tail;
struct mu_opool_bucket *free;
......@@ -69,7 +70,7 @@ alloc_bucket (struct _mu_opool *opool, size_t size)
static int
alloc_pool (mu_opool_t opool, size_t size)
{
struct mu_opool_bucket *p = alloc_bucket (opool, MU_OPOOL_BUCKET_SIZE);
struct mu_opool_bucket *p = alloc_bucket (opool, opool->bucket_size);
if (!p)
return ENOMEM;
if (opool->tail)
......@@ -86,7 +87,7 @@ copy_chars (mu_opool_t opool, const char *str, size_t n, size_t *psize)
size_t rest;
if (!opool->head || opool->tail->level == opool->tail->size)
if (alloc_pool (opool, MU_OPOOL_BUCKET_SIZE))
if (alloc_pool (opool, opool->bucket_size))
return ENOMEM;
rest = opool->tail->size - opool->tail->level;
if (n > rest)
......@@ -108,12 +109,31 @@ mu_opool_create (mu_opool_t *pret, int memerr)
return ENOMEM;
}
x->memerr = memerr;
x->bucket_size = MU_OPOOL_BUCKET_SIZE;
x->itr_count = 0;
x->head = x->tail = x->free = 0;
*pret = x;
return 0;
}
int
mu_opool_set_bucket_size (mu_opool_t opool, size_t size)
{
if (!opool)
return EINVAL;
opool->bucket_size = size;
return 0;
}
int
mu_opool_get_bucket_size (mu_opool_t opool, size_t *psize)
{
if (!opool || !psize)
return EINVAL;
*psize = opool->bucket_size;
return 0;
}
void
mu_opool_clear (mu_opool_t opool)
{
......