diff options
Diffstat (limited to 'src/pool.c')
-rw-r--r-- | src/pool.c | 106 |
1 files changed, 53 insertions, 53 deletions
@@ -26,46 +26,46 @@ #include <colm/pool.h> #include <colm/debug.h> -void init_pool_alloc( struct pool_alloc *poolAlloc, int sizeofT ) +void init_pool_alloc( struct pool_alloc *pool_alloc, int sizeofT ) { - poolAlloc->head = 0; - poolAlloc->nextel = FRESH_BLOCK; - poolAlloc->pool = 0; - poolAlloc->sizeofT = sizeofT; + pool_alloc->head = 0; + pool_alloc->nextel = FRESH_BLOCK; + pool_alloc->pool = 0; + pool_alloc->sizeofT = sizeofT; } -static void *pool_alloc_allocate( struct pool_alloc *poolAlloc ) +static void *pool_alloc_allocate( struct pool_alloc *pool_alloc ) { //debug( REALM_POOL, "pool allocation\n" ); #ifdef POOL_MALLOC - void *res = malloc( poolAlloc->sizeofT ); - memset( res, 0, poolAlloc->sizeofT ); + void *res = malloc( pool_alloc->sizeofT ); + memset( res, 0, pool_alloc->sizeofT ); return res; #else - void *newEl = 0; - if ( poolAlloc->pool == 0 ) { - if ( poolAlloc->nextel == FRESH_BLOCK ) { - struct pool_block *newBlock = (struct pool_block*)malloc( sizeof(struct pool_block) ); - newBlock->data = malloc( poolAlloc->sizeofT * FRESH_BLOCK ); - newBlock->next = poolAlloc->head; - poolAlloc->head = newBlock; - poolAlloc->nextel = 0; + void *new_el = 0; + if ( pool_alloc->pool == 0 ) { + if ( pool_alloc->nextel == FRESH_BLOCK ) { + struct pool_block *new_block = (struct pool_block*)malloc( sizeof(struct pool_block) ); + new_block->data = malloc( pool_alloc->sizeofT * FRESH_BLOCK ); + new_block->next = pool_alloc->head; + pool_alloc->head = new_block; + pool_alloc->nextel = 0; } - newEl = (char*)poolAlloc->head->data + poolAlloc->sizeofT * poolAlloc->nextel++; + new_el = (char*)pool_alloc->head->data + pool_alloc->sizeofT * pool_alloc->nextel++; } else { - newEl = poolAlloc->pool; - poolAlloc->pool = poolAlloc->pool->next; + new_el = pool_alloc->pool; + pool_alloc->pool = pool_alloc->pool->next; } - memset( newEl, 0, poolAlloc->sizeofT ); - return newEl; + memset( new_el, 0, pool_alloc->sizeofT ); + return new_el; #endif } -void pool_alloc_free( struct pool_alloc *poolAlloc, void *el ) +void pool_alloc_free( struct pool_alloc *pool_alloc, void *el ) { #if 0 /* Some sanity checking. Best not to normally run with this on. */ @@ -80,14 +80,14 @@ void pool_alloc_free( struct pool_alloc *poolAlloc, void *el ) free( el ); #else struct pool_item *pi = (struct pool_item*) el; - pi->next = poolAlloc->pool; - poolAlloc->pool = pi; + pi->next = pool_alloc->pool; + pool_alloc->pool = pi; #endif } -void pool_alloc_clear( struct pool_alloc *poolAlloc ) +void pool_alloc_clear( struct pool_alloc *pool_alloc ) { - struct pool_block *block = poolAlloc->head; + struct pool_block *block = pool_alloc->head; while ( block != 0 ) { struct pool_block *next = block->next; free( block->data ); @@ -95,18 +95,18 @@ void pool_alloc_clear( struct pool_alloc *poolAlloc ) block = next; } - poolAlloc->head = 0; - poolAlloc->nextel = 0; - poolAlloc->pool = 0; + pool_alloc->head = 0; + pool_alloc->nextel = 0; + pool_alloc->pool = 0; } -long pool_alloc_num_lost( struct pool_alloc *poolAlloc ) +long pool_alloc_num_lost( struct pool_alloc *pool_alloc ) { /* Count the number of items allocated. */ long lost = 0; - struct pool_block *block = poolAlloc->head; + struct pool_block *block = pool_alloc->head; if ( block != 0 ) { - lost = poolAlloc->nextel; + lost = pool_alloc->nextel; block = block->next; while ( block != 0 ) { lost += FRESH_BLOCK; @@ -115,7 +115,7 @@ long pool_alloc_num_lost( struct pool_alloc *poolAlloc ) } /* Subtract. Items that are on the free list. */ - struct pool_item *pi = poolAlloc->pool; + struct pool_item *pi = pool_alloc->pool; while ( pi != 0 ) { lost -= 1; pi = pi->next; @@ -130,22 +130,22 @@ long pool_alloc_num_lost( struct pool_alloc *poolAlloc ) kid_t *kid_allocate( program_t *prg ) { - return (kid_t*) pool_alloc_allocate( &prg->kidPool ); + return (kid_t*) pool_alloc_allocate( &prg->kid_pool ); } void kid_free( program_t *prg, kid_t *el ) { - pool_alloc_free( &prg->kidPool, el ); + pool_alloc_free( &prg->kid_pool, el ); } void kid_clear( program_t *prg ) { - pool_alloc_clear( &prg->kidPool ); + pool_alloc_clear( &prg->kid_pool ); } long kid_num_lost( program_t *prg ) { - return pool_alloc_num_lost( &prg->kidPool ); + return pool_alloc_num_lost( &prg->kid_pool ); } /* @@ -154,22 +154,22 @@ long kid_num_lost( program_t *prg ) tree_t *tree_allocate( program_t *prg ) { - return (tree_t*) pool_alloc_allocate( &prg->treePool ); + return (tree_t*) pool_alloc_allocate( &prg->tree_pool ); } void tree_free( program_t *prg, tree_t *el ) { - pool_alloc_free( &prg->treePool, el ); + pool_alloc_free( &prg->tree_pool, el ); } void tree_clear( program_t *prg ) { - pool_alloc_clear( &prg->treePool ); + pool_alloc_clear( &prg->tree_pool ); } long tree_num_lost( program_t *prg ) { - return pool_alloc_num_lost( &prg->treePool ); + return pool_alloc_num_lost( &prg->tree_pool ); } /* @@ -178,22 +178,22 @@ long tree_num_lost( program_t *prg ) parse_tree_t *parse_tree_allocate( program_t *prg ) { - return (parse_tree_t*) pool_alloc_allocate( &prg->parseTreePool ); + return (parse_tree_t*) pool_alloc_allocate( &prg->parse_tree_pool ); } void parse_tree_free( program_t *prg, parse_tree_t *el ) { - pool_alloc_free( &prg->parseTreePool, el ); + pool_alloc_free( &prg->parse_tree_pool, el ); } void parse_tree_clear( program_t *prg ) { - pool_alloc_clear( &prg->parseTreePool ); + pool_alloc_clear( &prg->parse_tree_pool ); } long parse_tree_num_lost( program_t *prg ) { - return pool_alloc_num_lost( &prg->parseTreePool ); + return pool_alloc_num_lost( &prg->parse_tree_pool ); } /* @@ -202,22 +202,22 @@ long parse_tree_num_lost( program_t *prg ) head_t *head_allocate( program_t *prg ) { - return (head_t*) pool_alloc_allocate( &prg->headPool ); + return (head_t*) pool_alloc_allocate( &prg->head_pool ); } void head_free( program_t *prg, head_t *el ) { - pool_alloc_free( &prg->headPool, el ); + pool_alloc_free( &prg->head_pool, el ); } void head_clear( program_t *prg ) { - pool_alloc_clear( &prg->headPool ); + pool_alloc_clear( &prg->head_pool ); } long head_num_lost( program_t *prg ) { - return pool_alloc_num_lost( &prg->headPool ); + return pool_alloc_num_lost( &prg->head_pool ); } /* @@ -226,20 +226,20 @@ long head_num_lost( program_t *prg ) location_t *location_allocate( program_t *prg ) { - return (location_t*) pool_alloc_allocate( &prg->locationPool ); + return (location_t*) pool_alloc_allocate( &prg->location_pool ); } void location_free( program_t *prg, location_t *el ) { - pool_alloc_free( &prg->locationPool, el ); + pool_alloc_free( &prg->location_pool, el ); } void location_clear( program_t *prg ) { - pool_alloc_clear( &prg->locationPool ); + pool_alloc_clear( &prg->location_pool ); } long location_num_lost( program_t *prg ) { - return pool_alloc_num_lost( &prg->locationPool ); + return pool_alloc_num_lost( &prg->location_pool ); } |