diff options
Diffstat (limited to 'src/H5FL.c')
-rw-r--r-- | src/H5FL.c | 188 |
1 files changed, 188 insertions, 0 deletions
@@ -105,6 +105,9 @@ static herr_t H5FL_arr_gc_list(H5FL_arr_head_t *head); static herr_t H5FL_blk_gc(void); static herr_t H5FL_blk_gc_list(H5FL_blk_head_t *head); +/* Declare a free list to manage the H5FL_fac_head_t struct */ +H5FL_DEFINE(H5FL_fac_head_t); + /* Declare a free list to manage the H5FL_blk_node_t struct */ H5FL_DEFINE(H5FL_blk_node_t); @@ -1775,6 +1778,191 @@ done: /*------------------------------------------------------------------------- + * Function: H5FL_fac_init + * + * Purpose: Initialize a block factory + * + * Return: Success: Pointer to factory object + * Failure: NULL + * + * Programmer: Quincey Koziol + * Wednesday, February 2, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +H5FL_fac_head_t * +H5FL_fac_init(size_t size) +{ + H5FL_fac_head_t *factory; /* Pointer to new block factory */ + H5FL_fac_head_t *ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5FL_fac_init, NULL) + + /* Sanity check */ + HDassert(size>0); + + /* Allocate room for the new factory */ + if(NULL==(factory=H5FL_MALLOC(H5FL_fac_head_t))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for factory object") + + /* Initialize block header information */ + HDmemset(&(factory->queue),0,sizeof(H5FL_blk_head_t)); + + /* Set size of blocks for factory */ + factory->size=size; + + /* Set return value */ + ret_value=factory; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FL_fac_init() */ + + +/*------------------------------------------------------------------------- + * Function: H5FL_fac_free + * + * Purpose: Release a block back to a factory & put on free list + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Quincey Koziol + * Wednesday, February 2, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +void * +H5FL_fac_free(H5FL_fac_head_t *head, void *obj) +{ + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FL_fac_free) + + /* Double check parameters */ + assert(head); + assert(obj); + + /* Make certain that the free list is initialized */ + assert(head->queue.init); + + /* Use block routine */ + H5FL_blk_free(&(head->queue),obj); + + FUNC_LEAVE_NOAPI(NULL) +} /* end H5FL_fac_free() */ + + +/*------------------------------------------------------------------------- + * Function: H5FL_fac_malloc + * + * Purpose: Allocate a block from a factory + * + * Return: Success: Pointer to a valid sequence object + * Failure: NULL + * + * Programmer: Quincey Koziol + * Wednesday, February 2, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +void * +H5FL_fac_malloc(H5FL_fac_head_t *head) +{ + void *ret_value; /* Pointer to object to return */ + + FUNC_ENTER_NOAPI(H5FL_fac_malloc, NULL) + + /* Double check parameters */ + assert(head); + + /* Use block routine */ + ret_value=H5FL_blk_malloc(&(head->queue),head->size); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FL_fac_malloc() */ + + +/*------------------------------------------------------------------------- + * Function: H5FL_fac_calloc + * + * Purpose: Allocate a block from a factory and clear it to zeros + * + * Return: Success: Pointer to a valid array object + * Failure: NULL + * + * Programmer: Quincey Koziol + * Wednesday, February 2, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +void * +H5FL_fac_calloc(H5FL_fac_head_t *head) +{ + void *ret_value; /* Pointer to object to return */ + + FUNC_ENTER_NOAPI(H5FL_fac_calloc, NULL) + + /* Double check parameters */ + assert(head); + + /* Use block routine */ + ret_value=H5FL_blk_calloc(&(head->queue),head->size); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FL_fac_calloc() */ + + +/*------------------------------------------------------------------------- + * Function: H5FL_fac_term + * + * Purpose: Terminate a block factory + * + * Return: Success: non-negative + * Failure: negative + * + * Programmer: Quincey Koziol + * Wednesday, February 2, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5FL_fac_term(H5FL_fac_head_t *factory) +{ + herr_t ret_value=SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5FL_fac_term) + + /* Sanity check */ + HDassert(factory); + + /* Garbage collect all the blocks in the factory's free list */ + if(H5FL_blk_gc_list(&(factory->queue))<0) + HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGC, FAIL, "garbage collection of factory failed") + + /* Verify that all the blocks have been freed */ + if(factory->queue.allocated>0) + HGOTO_ERROR(H5E_RESOURCE, H5E_CANTRELEASE, FAIL, "factory still has objects allocated") + + /* Free factory info */ + H5FL_FREE(H5FL_fac_head_t,factory); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FL_fac_term() */ + + +/*------------------------------------------------------------------------- * Function: H5FL_garbage_coll * * Purpose: Garbage collect on all the free lists |