diff options
Diffstat (limited to 'src/H5FLprivate.h')
-rw-r--r-- | src/H5FLprivate.h | 87 |
1 files changed, 73 insertions, 14 deletions
diff --git a/src/H5FLprivate.h b/src/H5FLprivate.h index 4f3d938..c1fbfae 100644 --- a/src/H5FLprivate.h +++ b/src/H5FLprivate.h @@ -39,6 +39,7 @@ #ifdef H5_NO_FREE_LISTS #define H5_NO_REG_FREE_LISTS #define H5_NO_ARR_FREE_LISTS +#define H5_NO_SEQ_FREE_LISTS #define H5_NO_BLK_FREE_LISTS #endif /* H5_NO_FREE_LISTS */ @@ -137,7 +138,7 @@ typedef struct H5FL_blk_head_t { #define H5FL_BLK_NAME(t) H5_##t##_blk_free_list #ifndef H5_NO_BLK_FREE_LISTS /* Common macro for H5FL_BLK_DEFINE & H5FL_BLK_DEFINE_STATIC */ -#define H5FL_BLK_DEFINE_COMMON(t) H5FL_blk_head_t H5FL_BLK_NAME(t)={0,0,0,0,#t,NULL} +#define H5FL_BLK_DEFINE_COMMON(t) H5FL_blk_head_t H5FL_BLK_NAME(t)={0,0,0,0,#t"_blk",NULL} /* Declare a free list to manage objects of type 't' */ #define H5FL_BLK_DEFINE(t) H5_DLL H5FL_BLK_DEFINE_COMMON(t) @@ -178,26 +179,29 @@ typedef struct H5FL_blk_head_t { #endif /* H5_NO_BLK_FREE_LISTS */ /* Data structure to store each array in free list */ -typedef union H5FL_arr_node_t { - union H5FL_arr_node_t *next; /* Pointer to next block in free list */ +typedef union H5FL_arr_list_t { + union H5FL_arr_list_t *next; /* Pointer to next block in free list */ size_t nelem; /* Number of elements in this array */ double unused1; /* Unused normally, just here for aligment */ haddr_t unused2; /* Unused normally, just here for aligment */ +} H5FL_arr_list_t; + +/* Data structure for each size of array element */ +typedef struct H5FL_arr_node_t { + size_t size; /* Size of the blocks in the list */ + unsigned onlist; /* Number of blocks on free list */ + H5FL_arr_list_t *list; /* List of free blocks */ } H5FL_arr_node_t; /* Data structure for free list of array blocks */ typedef struct H5FL_arr_head_t { unsigned init; /* Whether the free list has been initialized */ unsigned allocated; /* Number of blocks allocated */ - unsigned *onlist; /* Number of blocks on free list */ - size_t list_mem; /* Amount of memory in block on free list */ - const char *name; /* Name of the type */ - int maxelem; /* Maximum number of elements in an array */ - size_t size; /* Size of the array elements in the list */ - union { - H5FL_arr_node_t **list_arr; /* Array of lists of free blocks */ - H5FL_blk_head_t queue; /* Priority queue of array blocks */ - }u; + size_t list_mem; /* Amount of memory in block on free list */ + const char *name; /* Name of the type */ + int maxelem; /* Maximum number of elements in an array */ + size_t size; /* Size of the array elements in the list */ + H5FL_arr_node_t *list_arr; /* Array of lists of free blocks */ } H5FL_arr_head_t; /* @@ -206,7 +210,7 @@ typedef struct H5FL_arr_head_t { #define H5FL_ARR_NAME(t) H5_##t##_arr_free_list #ifndef H5_NO_ARR_FREE_LISTS /* Common macro for H5FL_BLK_DEFINE & H5FL_BLK_DEFINE_STATIC */ -#define H5FL_ARR_DEFINE_COMMON(t,m) H5FL_arr_head_t H5FL_ARR_NAME(t)={0,0,NULL,0,#t"_arr",m+1,sizeof(t),{NULL}} +#define H5FL_ARR_DEFINE_COMMON(t,m) H5FL_arr_head_t H5FL_ARR_NAME(t)={0,0,0,#t"_arr",m+1,sizeof(t),NULL} /* Declare a free list to manage arrays of type 't' */ #define H5FL_ARR_DEFINE(t,m) H5_DLL H5FL_ARR_DEFINE_COMMON(t,m) @@ -230,7 +234,7 @@ typedef struct H5FL_arr_head_t { #define H5FL_ARR_REALLOC(t,obj,new_elem) H5FL_arr_realloc(&(H5FL_ARR_NAME(t)),obj,new_elem) #else /* H5_NO_ARR_FREE_LISTS */ -/* Common macro for H5FL_BLK_DEFINE & H5FL_BLK_DEFINE_STATIC */ +/* Common macro for H5FL_ARR_DEFINE & H5FL_ARR_DEFINE_STATIC */ #define H5FL_ARR_DEFINE_COMMON(t,m) int H5FL_ARR_NAME(t) #define H5FL_ARR_DEFINE(t,m) H5_DLL H5FL_ARR_DEFINE_COMMON(t,m) @@ -242,6 +246,57 @@ typedef struct H5FL_arr_head_t { #define H5FL_ARR_REALLOC(t,obj,new_elem) H5MM_realloc(obj,(new_elem)*sizeof(t)) #endif /* H5_NO_ARR_FREE_LISTS */ +/* Data structure for free list of sequence blocks */ +typedef struct H5FL_seq_head_t { + H5FL_blk_head_t queue; /* Priority queue of sequence blocks */ + size_t size; /* Size of the sequence elements in the list */ +} H5FL_seq_head_t; + +/* + * Macros for defining & using free lists for a sequence of a type + * + * Sequences are like arrays, except they have no upper limit. + * + */ +#define H5FL_SEQ_NAME(t) H5_##t##_seq_free_list +#ifndef H5_NO_SEQ_FREE_LISTS +/* Common macro for H5FL_SEQ_DEFINE & H5FL_SEQ_DEFINE_STATIC */ +#define H5FL_SEQ_DEFINE_COMMON(t) H5FL_seq_head_t H5FL_SEQ_NAME(t)={{0,0,0,0,#t"_seq",NULL},sizeof(t)} + +/* Declare a free list to manage sequences of type 't' */ +#define H5FL_SEQ_DEFINE(t) H5_DLL H5FL_SEQ_DEFINE_COMMON(t) + +/* Reference a free list for sequences of type 't' defined in another file */ +#define H5FL_SEQ_EXTERN(t) extern H5_DLL H5FL_seq_head_t H5FL_SEQ_NAME(t) + +/* Declare a static free list to manage sequences of type 't' */ +#define H5FL_SEQ_DEFINE_STATIC(t) static H5FL_SEQ_DEFINE_COMMON(t) + +/* Allocate a sequence of type 't' */ +#define H5FL_SEQ_MALLOC(t,elem) H5FL_seq_malloc(&(H5FL_SEQ_NAME(t)),elem) + +/* Allocate a sequence of type 't' and clear it to all zeros */ +#define H5FL_SEQ_CALLOC(t,elem) H5FL_seq_calloc(&(H5FL_SEQ_NAME(t)),elem) + +/* Free a sequence of type 't' */ +#define H5FL_SEQ_FREE(t,obj) H5FL_seq_free(&(H5FL_SEQ_NAME(t)),obj) + +/* Re-allocate a sequence of type 't' */ +#define H5FL_SEQ_REALLOC(t,obj,new_elem) H5FL_seq_realloc(&(H5FL_SEQ_NAME(t)),obj,new_elem) + +#else /* H5_NO_SEQ_FREE_LISTS */ +/* Common macro for H5FL_BLK_DEFINE & H5FL_BLK_DEFINE_STATIC */ +#define H5FL_SEQ_DEFINE_COMMON(t) int H5FL_SEQ_NAME(t) + +#define H5FL_SEQ_DEFINE(t) H5_DLL H5FL_SEQ_DEFINE_COMMON(t) +#define H5FL_SEQ_EXTERN(t) extern H5_DLL int H5FL_SEQ_NAME(t) +#define H5FL_SEQ_DEFINE_STATIC(t) static H5FL_SEQ_DEFINE_COMMON(t) +#define H5FL_SEQ_MALLOC(t,elem) H5MM_malloc((elem)*sizeof(t)) +#define H5FL_SEQ_CALLOC(t,elem) H5MM_calloc((elem)*sizeof(t)) +#define H5FL_SEQ_FREE(t,obj) H5MM_xfree(obj) +#define H5FL_SEQ_REALLOC(t,obj,new_elem) H5MM_realloc(obj,(new_elem)*sizeof(t)) +#endif /* H5_NO_SEQ_FREE_LISTS */ + /* * Library prototypes. */ @@ -257,6 +312,10 @@ H5_DLL void * H5FL_arr_malloc(H5FL_arr_head_t *head, size_t elem); H5_DLL void * H5FL_arr_calloc(H5FL_arr_head_t *head, size_t elem); H5_DLL void * H5FL_arr_free(H5FL_arr_head_t *head, void *obj); H5_DLL void * H5FL_arr_realloc(H5FL_arr_head_t *head, void *obj, size_t new_elem); +H5_DLL void * H5FL_seq_malloc(H5FL_seq_head_t *head, size_t elem); +H5_DLL void * H5FL_seq_calloc(H5FL_seq_head_t *head, size_t elem); +H5_DLL void * H5FL_seq_free(H5FL_seq_head_t *head, void *obj); +H5_DLL void * H5FL_seq_realloc(H5FL_seq_head_t *head, void *obj, size_t new_elem); H5_DLL herr_t H5FL_garbage_coll(void); H5_DLL herr_t H5FL_set_free_list_limits(int reg_global_lim, int reg_list_lim, int arr_global_lim, int arr_list_lim, int blk_global_lim, int blk_list_lim); |