diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2020-09-30 14:27:10 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2020-09-30 14:27:10 (GMT) |
commit | b2d661b508a7fc7a2592c13bc6bdc175551f075d (patch) | |
tree | 13baeb0d83a7c2a4c6299993c182b1227c2f6114 /src/H5HGcache.c | |
parent | 29ab58b58dce556639ea3154e262895773a8a8df (diff) | |
download | hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.zip hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.gz hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.bz2 |
Clang-format of source files
Diffstat (limited to 'src/H5HGcache.c')
-rw-r--r-- | src/H5HGcache.c | 154 |
1 files changed, 66 insertions, 88 deletions
diff --git a/src/H5HGcache.c b/src/H5HGcache.c index f85df33..5cc2790 100644 --- a/src/H5HGcache.c +++ b/src/H5HGcache.c @@ -26,54 +26,45 @@ /* Module Setup */ /****************/ -#include "H5HGmodule.h" /* This source code file is part of the H5HG module */ - +#include "H5HGmodule.h" /* This source code file is part of the H5HG module */ /***********/ /* Headers */ /***********/ -#include "H5private.h" /* Generic Functions */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5Fprivate.h" /* File access */ -#include "H5HGpkg.h" /* Global heaps */ -#include "H5MFprivate.h" /* File memory management */ -#include "H5MMprivate.h" /* Memory management */ - +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Fprivate.h" /* File access */ +#include "H5HGpkg.h" /* Global heaps */ +#include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ /****************/ /* Local Macros */ /****************/ - /******************/ /* Local Typedefs */ /******************/ - /********************/ /* Package Typedefs */ /********************/ - /********************/ /* Local Prototypes */ /********************/ /* Metadata cache callbacks */ static herr_t H5HG__cache_heap_get_initial_load_size(void *udata, size_t *image_len); -static herr_t H5HG__cache_heap_get_final_load_size(const void *_image, - size_t image_len, void *udata, size_t *actual_len); -static void *H5HG__cache_heap_deserialize(const void *image, size_t len, - void *udata, hbool_t *dirty); +static herr_t H5HG__cache_heap_get_final_load_size(const void *_image, size_t image_len, void *udata, + size_t *actual_len); +static void * H5HG__cache_heap_deserialize(const void *image, size_t len, void *udata, hbool_t *dirty); static herr_t H5HG__cache_heap_image_len(const void *thing, size_t *image_len); -static herr_t H5HG__cache_heap_serialize(const H5F_t *f, void *image, - size_t len, void *thing); +static herr_t H5HG__cache_heap_serialize(const H5F_t *f, void *image, size_t len, void *thing); static herr_t H5HG__cache_heap_free_icr(void *thing); /* Prefix deserialization */ -static herr_t H5HG__hdr_deserialize(H5HG_heap_t *heap, const uint8_t *image, - const H5F_t *f); - +static herr_t H5HG__hdr_deserialize(H5HG_heap_t *heap, const uint8_t *image, const H5F_t *f); /*********************/ /* Package Variables */ @@ -81,34 +72,30 @@ static herr_t H5HG__hdr_deserialize(H5HG_heap_t *heap, const uint8_t *image, /* H5HG inherits cache-like properties from H5AC */ const H5AC_class_t H5AC_GHEAP[1] = {{ - H5AC_GHEAP_ID, /* Metadata client ID */ - "global heap", /* Metadata client name (for debugging) */ - H5FD_MEM_GHEAP, /* File space memory type for client */ - H5AC__CLASS_SPECULATIVE_LOAD_FLAG, /* Client class behavior flags */ - H5HG__cache_heap_get_initial_load_size, /* 'get_initial_load_size' callback */ - H5HG__cache_heap_get_final_load_size, /* 'get_final_load_size' callback */ - NULL, /* 'verify_chksum' callback */ - H5HG__cache_heap_deserialize, /* 'deserialize' callback */ - H5HG__cache_heap_image_len, /* 'image_len' callback */ - NULL, /* 'pre_serialize' callback */ - H5HG__cache_heap_serialize, /* 'serialize' callback */ - NULL, /* 'notify' callback */ - H5HG__cache_heap_free_icr, /* 'free_icr' callback */ - NULL, /* 'fsf_size' callback */ + H5AC_GHEAP_ID, /* Metadata client ID */ + "global heap", /* Metadata client name (for debugging) */ + H5FD_MEM_GHEAP, /* File space memory type for client */ + H5AC__CLASS_SPECULATIVE_LOAD_FLAG, /* Client class behavior flags */ + H5HG__cache_heap_get_initial_load_size, /* 'get_initial_load_size' callback */ + H5HG__cache_heap_get_final_load_size, /* 'get_final_load_size' callback */ + NULL, /* 'verify_chksum' callback */ + H5HG__cache_heap_deserialize, /* 'deserialize' callback */ + H5HG__cache_heap_image_len, /* 'image_len' callback */ + NULL, /* 'pre_serialize' callback */ + H5HG__cache_heap_serialize, /* 'serialize' callback */ + NULL, /* 'notify' callback */ + H5HG__cache_heap_free_icr, /* 'free_icr' callback */ + NULL, /* 'fsf_size' callback */ }}; - /*****************************/ /* Library Private Variables */ /*****************************/ - /*******************/ /* Local Variables */ /*******************/ - - /*------------------------------------------------------------------------- * Function: H5HG__hdr_deserialize() * @@ -125,7 +112,7 @@ const H5AC_class_t H5AC_GHEAP[1] = {{ static herr_t H5HG__hdr_deserialize(H5HG_heap_t *heap, const uint8_t *image, const H5F_t *f) { - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -135,12 +122,12 @@ H5HG__hdr_deserialize(H5HG_heap_t *heap, const uint8_t *image, const H5F_t *f) HDassert(f); /* Magic number */ - if(HDmemcmp(image, H5HG_MAGIC, (size_t)H5_SIZEOF_MAGIC)) + if (HDmemcmp(image, H5HG_MAGIC, (size_t)H5_SIZEOF_MAGIC)) HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, FAIL, "bad global heap collection signature") image += H5_SIZEOF_MAGIC; /* Version */ - if(H5HG_VERSION != *image++) + if (H5HG_VERSION != *image++) HGOTO_ERROR(H5E_HEAP, H5E_VERSION, FAIL, "wrong version number in global heap") /* Reserved */ @@ -154,7 +141,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5HG__hdr_deserialize() */ - /*------------------------------------------------------------------------- * Function: H5HG__cache_heap_get_initial_load_size() * @@ -186,7 +172,6 @@ H5HG__cache_heap_get_initial_load_size(void H5_ATTR_UNUSED *_udata, size_t *imag FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5HG__cache_heap_get_initial_load_size() */ - /*------------------------------------------------------------------------- * Function: H5HG__cache_heap_get_initial_load_size() * @@ -202,11 +187,11 @@ H5HG__cache_heap_get_initial_load_size(void H5_ATTR_UNUSED *_udata, size_t *imag *------------------------------------------------------------------------- */ static herr_t -H5HG__cache_heap_get_final_load_size(const void *image, size_t H5_ATTR_NDEBUG_UNUSED image_len, - void *udata, size_t *actual_len) +H5HG__cache_heap_get_final_load_size(const void *image, size_t H5_ATTR_NDEBUG_UNUSED image_len, void *udata, + size_t *actual_len) { - H5HG_heap_t heap; /* Global heap */ - herr_t ret_value = SUCCEED; /* Return value */ + H5HG_heap_t heap; /* Global heap */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -218,7 +203,7 @@ H5HG__cache_heap_get_final_load_size(const void *image, size_t H5_ATTR_NDEBUG_UN HDassert(image_len == H5HG_MINSIZE); /* Deserialize the heap's header */ - if(H5HG__hdr_deserialize(&heap, (const uint8_t *)image, (const H5F_t *)udata) < 0) + if (H5HG__hdr_deserialize(&heap, (const uint8_t *)image, (const H5F_t *)udata) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTDECODE, FAIL, "can't decode global heap prefix") /* Set the final size for the cache image */ @@ -228,7 +213,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5HG__cache_heap_get_final_load_size() */ - /*------------------------------------------------------------------------- * Function: H5HG__cache_heap_deserialize * @@ -245,15 +229,14 @@ done: *------------------------------------------------------------------------- */ static void * -H5HG__cache_heap_deserialize(const void *_image, size_t len, void *_udata, - hbool_t H5_ATTR_UNUSED *dirty) +H5HG__cache_heap_deserialize(const void *_image, size_t len, void *_udata, hbool_t H5_ATTR_UNUSED *dirty) { - H5F_t *f = (H5F_t *)_udata; /* File pointer -- obtained from user data */ - H5HG_heap_t *heap = NULL; /* New global heap */ - uint8_t *image; /* Pointer to image to decode */ - size_t max_idx = 0; /* Maximum heap object index seen */ - size_t nalloc; /* Number of objects allocated */ - void *ret_value = NULL; /* Return value */ + H5F_t * f = (H5F_t *)_udata; /* File pointer -- obtained from user data */ + H5HG_heap_t *heap = NULL; /* New global heap */ + uint8_t * image; /* Pointer to image to decode */ + size_t max_idx = 0; /* Maximum heap object index seen */ + size_t nalloc; /* Number of objects allocated */ + void * ret_value = NULL; /* Return value */ FUNC_ENTER_STATIC @@ -264,59 +247,59 @@ H5HG__cache_heap_deserialize(const void *_image, size_t len, void *_udata, HDassert(dirty); /* Allocate a new global heap */ - if(NULL == (heap = H5FL_CALLOC(H5HG_heap_t))) + if (NULL == (heap = H5FL_CALLOC(H5HG_heap_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") heap->shared = H5F_SHARED(f); - if(NULL == (heap->chunk = H5FL_BLK_MALLOC(gheap_chunk, len))) + if (NULL == (heap->chunk = H5FL_BLK_MALLOC(gheap_chunk, len))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Copy the image buffer into the newly allocate chunk */ H5MM_memcpy(heap->chunk, _image, len); /* Deserialize the heap's header */ - if(H5HG__hdr_deserialize(heap, (const uint8_t *)heap->chunk, f) < 0) + if (H5HG__hdr_deserialize(heap, (const uint8_t *)heap->chunk, f) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTDECODE, NULL, "can't decode global heap header") /* Decode each object */ - image = heap->chunk + H5HG_SIZEOF_HDR(f); + image = heap->chunk + H5HG_SIZEOF_HDR(f); nalloc = H5HG_NOBJS(f, heap->size); /* Calloc the obj array because the file format spec makes no guarantee * about the order of the objects, and unused slots must be set to zero. */ - if(NULL == (heap->obj = H5FL_SEQ_CALLOC(H5HG_obj_t, nalloc))) + if (NULL == (heap->obj = H5FL_SEQ_CALLOC(H5HG_obj_t, nalloc))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") heap->nalloc = nalloc; - while(image < (heap->chunk + heap->size)) { - if((image + H5HG_SIZEOF_OBJHDR(f)) > (heap->chunk + heap->size)) { + while (image < (heap->chunk + heap->size)) { + if ((image + H5HG_SIZEOF_OBJHDR(f)) > (heap->chunk + heap->size)) { /* * The last bit of space is too tiny for an object header, so * we assume that it's free space. */ HDassert(NULL == heap->obj[0].begin); - heap->obj[0].size = (size_t)(((const uint8_t *)heap->chunk + heap->size) - image); + heap->obj[0].size = (size_t)(((const uint8_t *)heap->chunk + heap->size) - image); heap->obj[0].begin = image; image += heap->obj[0].size; } /* end if */ else { - size_t need = 0; + size_t need = 0; unsigned idx; uint8_t *begin = image; UINT16DECODE(image, idx); /* Check if we need more room to store heap objects */ - if(idx >= heap->nalloc) { - size_t new_alloc; /* New allocation number */ - H5HG_obj_t *new_obj; /* New array of object descriptions */ + if (idx >= heap->nalloc) { + size_t new_alloc; /* New allocation number */ + H5HG_obj_t *new_obj; /* New array of object descriptions */ /* Determine the new number of objects to index */ new_alloc = MAX(heap->nalloc * 2, (idx + 1)); HDassert(idx < new_alloc); /* Reallocate array of objects */ - if(NULL == (new_obj = H5FL_SEQ_REALLOC(H5HG_obj_t, heap->obj, new_alloc))) + if (NULL == (new_obj = H5FL_SEQ_REALLOC(H5HG_obj_t, heap->obj, new_alloc))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Clear newly allocated space */ @@ -324,7 +307,7 @@ H5HG__cache_heap_deserialize(const void *_image, size_t len, void *_udata, /* Update heap information */ heap->nalloc = new_alloc; - heap->obj = new_obj; + heap->obj = new_obj; HDassert(heap->nalloc > heap->nused); } /* end if */ @@ -341,9 +324,9 @@ H5HG__cache_heap_deserialize(const void *_image, size_t len, void *_udata, * is the free space object whose size is never padded and * already includes the object header. */ - if(idx > 0) { + if (idx > 0) { need = H5HG_SIZEOF_OBJHDR(f) + H5HG_ALIGN(heap->obj[idx].size); - if(idx > max_idx) + if (idx > max_idx) max_idx = idx; } /* end if */ else @@ -351,14 +334,14 @@ H5HG__cache_heap_deserialize(const void *_image, size_t len, void *_udata, image = begin + need; } /* end else */ - } /* end while */ + } /* end while */ /* Sanity checks */ HDassert(image == heap->chunk + heap->size); HDassert(H5HG_ISALIGNED(heap->obj[0].size)); /* Set the next index value to use */ - if(max_idx > 0) + if (max_idx > 0) heap->nused = max_idx + 1; else heap->nused = 1; @@ -367,20 +350,19 @@ H5HG__cache_heap_deserialize(const void *_image, size_t len, void *_udata, HDassert(max_idx < heap->nused); /* Add the new heap to the CWFS list for the file */ - if(H5F_cwfs_add(f, heap) < 0) + if (H5F_cwfs_add(f, heap) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, NULL, "unable to add global heap collection to file's CWFS") ret_value = heap; done: - if(!ret_value && heap) - if(H5HG__free(heap) < 0) + if (!ret_value && heap) + if (H5HG__free(heap) < 0) HDONE_ERROR(H5E_HEAP, H5E_CANTFREE, NULL, "unable to destroy global heap collection") FUNC_LEAVE_NOAPI(ret_value) } /* end H5HG__cache_heap_deserialize() */ - /*------------------------------------------------------------------------- * Function: H5HG__cache_heap_image_len * @@ -414,7 +396,6 @@ H5HG__cache_heap_image_len(const void *_thing, size_t *image_len) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5HG__cache_heap_image_len() */ - /*------------------------------------------------------------------------- * Function: H5HG__cache_heap_serialize * @@ -432,8 +413,7 @@ H5HG__cache_heap_image_len(const void *_thing, size_t *image_len) *------------------------------------------------------------------------- */ static herr_t -H5HG__cache_heap_serialize(const H5F_t H5_ATTR_NDEBUG_UNUSED *f, void *image, size_t len, - void *_thing) +H5HG__cache_heap_serialize(const H5F_t H5_ATTR_NDEBUG_UNUSED *f, void *image, size_t len, void *_thing) { H5HG_heap_t *heap = (H5HG_heap_t *)_thing; @@ -453,7 +433,6 @@ H5HG__cache_heap_serialize(const H5F_t H5_ATTR_NDEBUG_UNUSED *f, void *image, si FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5HG__cache_heap_serialize() */ - /*------------------------------------------------------------------------- * Function: H5HG__cache_heap_free_icr * @@ -474,8 +453,8 @@ H5HG__cache_heap_serialize(const H5F_t H5_ATTR_NDEBUG_UNUSED *f, void *image, si static herr_t H5HG__cache_heap_free_icr(void *_thing) { - H5HG_heap_t *heap = (H5HG_heap_t *)_thing; - herr_t ret_value = SUCCEED; /* Return value */ + H5HG_heap_t *heap = (H5HG_heap_t *)_thing; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -485,10 +464,9 @@ H5HG__cache_heap_free_icr(void *_thing) HDassert(heap->cache_info.type == H5AC_GHEAP); /* Destroy global heap collection */ - if(H5HG__free(heap) < 0) + if (H5HG__free(heap) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to destroy global heap collection") done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5HG__cache_heap_free_icr() */ - |