style cleanup for mempool

This commit is contained in:
Campbell Barton 2012-03-01 23:14:51 +00:00
parent bc767059cb
commit c26f5035b6
2 changed files with 62 additions and 46 deletions

@ -48,7 +48,7 @@ typedef struct BLI_mempool BLI_mempool;
* first four bytes of the elements never contain the character string
* 'free'. use with care.*/
BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk, int flag);
BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag);
void *BLI_mempool_alloc(BLI_mempool *pool);
void *BLI_mempool_calloc(BLI_mempool *pool);
void BLI_mempool_free(BLI_mempool *pool, void *addr);

@ -81,27 +81,43 @@ struct BLI_mempool {
#define MEMPOOL_ELEM_SIZE_MIN (sizeof(void *) * 2)
BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk, int flag)
BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag)
{
BLI_mempool *pool = NULL;
BLI_freenode *lasttail = NULL, *curnode = NULL;
int i,j, maxchunks;
char *addr;
if (esize < MEMPOOL_ELEM_SIZE_MIN)
esize = MEMPOOL_ELEM_SIZE_MIN;
/* allocate the pool structure */
pool = (flag & BLI_MEMPOOL_SYSMALLOC) ? malloc(sizeof(BLI_mempool)) : MEM_mallocN(sizeof(BLI_mempool), "memory pool");
pool->esize = (flag & BLI_MEMPOOL_ALLOW_ITER) ? MAX2(esize, sizeof(BLI_freenode)) : esize;
if (flag & BLI_MEMPOOL_SYSMALLOC) {
pool = malloc(sizeof(BLI_mempool));
}
else {
pool = MEM_mallocN(sizeof(BLI_mempool), "memory pool");
}
/* set the elem size */
if (esize < MEMPOOL_ELEM_SIZE_MIN) {
esize = MEMPOOL_ELEM_SIZE_MIN;
}
if (flag & BLI_MEMPOOL_ALLOW_ITER) {
pool->esize = MAX2(esize, sizeof(BLI_freenode));
}
else {
pool->esize = esize;
}
pool->flag = flag;
pool->pchunk = pchunk;
pool->csize = esize * pchunk;
pool->chunks.first = pool->chunks.last = NULL;
pool->totused = 0;
maxchunks = tote / pchunk + 1;
if (maxchunks==0) maxchunks = 1;
maxchunks = totelem / pchunk + 1;
if (maxchunks == 0) {
maxchunks = 1;
}
/* allocate the actual chunks */
for (i = 0; i < maxchunks; i++) {
@ -137,7 +153,7 @@ BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk, int flag)
curnode->freeword = FREEWORD;
}
}
/*final pointer in the previously allocated chunk is wrong.*/
/* final pointer in the previously allocated chunk is wrong */
if (lasttail) {
lasttail->next = mpchunk->data;
if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) {