diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2008-11-27 23:08:46 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2008-11-27 23:08:46 +0000 |
commit | 9570a2451e0c378e55d53e4cccaf0fff1eb44f06 (patch) | |
tree | e4d3d746f3c6a4b779d2a42a467de0047c00bd5e | |
parent | 28e9a0a06b996595db2dd7ad64c9adced80d3aca (diff) | |
download | mailutils-9570a2451e0c378e55d53e4cccaf0fff1eb44f06.tar.gz mailutils-9570a2451e0c378e55d53e4cccaf0fff1eb44f06.tar.bz2 |
* 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.
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | include/mailutils/opool.h | 2 | ||||
-rw-r--r-- | mailbox/opool.c | 24 |
3 files changed, 36 insertions, 2 deletions
@@ -1,3 +1,15 @@ +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. diff --git a/include/mailutils/opool.h b/include/mailutils/opool.h index ed3b400dd..5cb16c13e 100644 --- a/include/mailutils/opool.h +++ b/include/mailutils/opool.h @@ -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. */ diff --git a/mailbox/opool.c b/mailbox/opool.c index 7fa060a58..06fa31a30 100644 --- a/mailbox/opool.c +++ b/mailbox/opool.c @@ -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) { |