* 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.
Showing
3 changed files
with
36 additions
and
2 deletions
1 | 2008-11-28 Sergey Poznyakoff <gray@gnu.org.ua> | ||
2 | |||
3 | * include/mailutils/opool.h (mu_opool_set_bucket_size) | ||
4 | (mu_opool_get_bucket_size): New protos. | ||
5 | * mailbox/opool.c (struct _mu_opool.bucket_size): New member. | ||
6 | (alloc_pool, copy_chars): Use opool->bucket_size to set bucket | ||
7 | size. | ||
8 | (mu_opool_create): Initialize bucket_size with the default | ||
9 | value. | ||
10 | (mu_opool_set_bucket_size,mu_opool_get_bucket_size): New | ||
11 | functions. | ||
12 | |||
1 | 2008-11-27 Sergey Poznyakoff <gray@gnu.org.ua> | 13 | 2008-11-27 Sergey Poznyakoff <gray@gnu.org.ua> |
2 | 14 | ||
3 | Add iterator support to opool. | 15 | Add iterator support to opool. | ... | ... |
... | @@ -29,6 +29,8 @@ | ... | @@ -29,6 +29,8 @@ |
29 | resulting pool (including mu_opool_create itself) will abort on | 29 | resulting pool (including mu_opool_create itself) will abort on |
30 | not enough memory condition, using mu_alloc_die. */ | 30 | not enough memory condition, using mu_alloc_die. */ |
31 | int mu_opool_create (mu_opool_t *pret, int memerr); | 31 | int mu_opool_create (mu_opool_t *pret, int memerr); |
32 | int mu_opool_set_bucket_size (mu_opool_t opool, size_t size); | ||
33 | int mu_opool_get_bucket_size (mu_opool_t opool, size_t *psize); | ||
32 | 34 | ||
33 | /* Clear all data from the pool, so next mu_opool_append* call will | 35 | /* Clear all data from the pool, so next mu_opool_append* call will |
34 | begin a new object. */ | 36 | begin a new object. */ | ... | ... |
... | @@ -42,6 +42,7 @@ struct mu_opool_bucket | ... | @@ -42,6 +42,7 @@ struct mu_opool_bucket |
42 | struct _mu_opool | 42 | struct _mu_opool |
43 | { | 43 | { |
44 | int memerr; | 44 | int memerr; |
45 | size_t bucket_size; | ||
45 | size_t itr_count; | 46 | size_t itr_count; |
46 | struct mu_opool_bucket *head, *tail; | 47 | struct mu_opool_bucket *head, *tail; |
47 | struct mu_opool_bucket *free; | 48 | struct mu_opool_bucket *free; |
... | @@ -69,7 +70,7 @@ alloc_bucket (struct _mu_opool *opool, size_t size) | ... | @@ -69,7 +70,7 @@ alloc_bucket (struct _mu_opool *opool, size_t size) |
69 | static int | 70 | static int |
70 | alloc_pool (mu_opool_t opool, size_t size) | 71 | alloc_pool (mu_opool_t opool, size_t size) |
71 | { | 72 | { |
72 | struct mu_opool_bucket *p = alloc_bucket (opool, MU_OPOOL_BUCKET_SIZE); | 73 | struct mu_opool_bucket *p = alloc_bucket (opool, opool->bucket_size); |
73 | if (!p) | 74 | if (!p) |
74 | return ENOMEM; | 75 | return ENOMEM; |
75 | if (opool->tail) | 76 | if (opool->tail) |
... | @@ -86,7 +87,7 @@ copy_chars (mu_opool_t opool, const char *str, size_t n, size_t *psize) | ... | @@ -86,7 +87,7 @@ copy_chars (mu_opool_t opool, const char *str, size_t n, size_t *psize) |
86 | size_t rest; | 87 | size_t rest; |
87 | 88 | ||
88 | if (!opool->head || opool->tail->level == opool->tail->size) | 89 | if (!opool->head || opool->tail->level == opool->tail->size) |
89 | if (alloc_pool (opool, MU_OPOOL_BUCKET_SIZE)) | 90 | if (alloc_pool (opool, opool->bucket_size)) |
90 | return ENOMEM; | 91 | return ENOMEM; |
91 | rest = opool->tail->size - opool->tail->level; | 92 | rest = opool->tail->size - opool->tail->level; |
92 | if (n > rest) | 93 | if (n > rest) |
... | @@ -108,12 +109,31 @@ mu_opool_create (mu_opool_t *pret, int memerr) | ... | @@ -108,12 +109,31 @@ mu_opool_create (mu_opool_t *pret, int memerr) |
108 | return ENOMEM; | 109 | return ENOMEM; |
109 | } | 110 | } |
110 | x->memerr = memerr; | 111 | x->memerr = memerr; |
112 | x->bucket_size = MU_OPOOL_BUCKET_SIZE; | ||
111 | x->itr_count = 0; | 113 | x->itr_count = 0; |
112 | x->head = x->tail = x->free = 0; | 114 | x->head = x->tail = x->free = 0; |
113 | *pret = x; | 115 | *pret = x; |
114 | return 0; | 116 | return 0; |
115 | } | 117 | } |
116 | 118 | ||
119 | int | ||
120 | mu_opool_set_bucket_size (mu_opool_t opool, size_t size) | ||
121 | { | ||
122 | if (!opool) | ||
123 | return EINVAL; | ||
124 | opool->bucket_size = size; | ||
125 | return 0; | ||
126 | } | ||
127 | |||
128 | int | ||
129 | mu_opool_get_bucket_size (mu_opool_t opool, size_t *psize) | ||
130 | { | ||
131 | if (!opool || !psize) | ||
132 | return EINVAL; | ||
133 | *psize = opool->bucket_size; | ||
134 | return 0; | ||
135 | } | ||
136 | |||
117 | void | 137 | void |
118 | mu_opool_clear (mu_opool_t opool) | 138 | mu_opool_clear (mu_opool_t opool) |
119 | { | 139 | { | ... | ... |
-
Please register or sign in to post a comment