diff options
author | Dana Robinson <derobins@hdfgroup.org> | 2022-04-13 21:17:29 (GMT) |
---|---|---|
committer | Dana Robinson <derobins@hdfgroup.org> | 2022-04-13 21:17:29 (GMT) |
commit | cabc39c3e197e2591449d2604bfee26465fb60e1 (patch) | |
tree | d5f39f5f5965584bf9bf49646a2af617adfd3e4e /src/H5Bcache.c | |
parent | 7355f4c505092a7a85474b47f18d5206028e2c95 (diff) | |
parent | ab69f5df770ee3cc6cd6c81d905a5317b894a002 (diff) | |
download | hdf5-feature/coding_standards.zip hdf5-feature/coding_standards.tar.gz hdf5-feature/coding_standards.tar.bz2 |
Merge branch 'develop' into feature/coding_standardsfeature/coding_standards
Diffstat (limited to 'src/H5Bcache.c')
-rw-r--r-- | src/H5Bcache.c | 164 |
1 files changed, 72 insertions, 92 deletions
diff --git a/src/H5Bcache.c b/src/H5Bcache.c index c2c7a80..0c179d7 100644 --- a/src/H5Bcache.c +++ b/src/H5Bcache.c @@ -6,7 +6,7 @@ * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * distribution tree, or in https://www.hdfgroup.org/licenses. * * If you do not have access to either file, you may request a copy from * * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -15,7 +15,7 @@ * * Created: H5Bcache.c * Oct 31 2005 - * Quincey Koziol <koziol@ncsa.uiuc.edu> + * Quincey Koziol * * Purpose: Implement B-tree metadata cache methods. * @@ -26,70 +26,61 @@ /* Module Setup */ /****************/ -#include "H5Bmodule.h" /* This source code file is part of the H5B module */ - +#include "H5Bmodule.h" /* This source code file is part of the H5B module */ /***********/ /* Headers */ /***********/ -#include "H5private.h" /* Generic Functions */ -#include "H5Bpkg.h" /* B-link trees */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5MMprivate.h" /* Memory management */ - +#include "H5private.h" /* Generic Functions */ +#include "H5Bpkg.h" /* B-link trees */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5MMprivate.h" /* Memory management */ /****************/ /* Local Macros */ /****************/ - /******************/ /* Local Typedefs */ /******************/ - /********************/ /* Local Prototypes */ /********************/ /* Metadata cache callbacks */ static herr_t H5B__cache_get_initial_load_size(void *udata, size_t *image_len); -static void *H5B__cache_deserialize(const void *image, size_t len, void *udata, - hbool_t *dirty); +static void * H5B__cache_deserialize(const void *image, size_t len, void *udata, hbool_t *dirty); static herr_t H5B__cache_image_len(const void *thing, size_t *image_len); -static herr_t H5B__cache_serialize(const H5F_t *f, void *image, size_t len, - void *thing); +static herr_t H5B__cache_serialize(const H5F_t *f, void *image, size_t len, void *thing); static herr_t H5B__cache_free_icr(void *thing); - /*********************/ /* Package Variables */ /*********************/ /* H5B inherits cache-like properties from H5AC */ const H5AC_class_t H5AC_BT[1] = {{ - H5AC_BT_ID, /* Metadata client ID */ - "v1 B-tree", /* Metadata client name (for debugging) */ - H5FD_MEM_BTREE, /* File space memory type for client */ - H5AC__CLASS_NO_FLAGS_SET, /* Client class behavior flags */ - H5B__cache_get_initial_load_size, /* 'get_initial_load_size' callback */ - NULL, /* 'get_final_load_size' callback */ - NULL, /* 'verify_chksum' callback */ - H5B__cache_deserialize, /* 'deserialize' callback */ - H5B__cache_image_len, /* 'image_len' callback */ - NULL, /* 'pre_serialize' callback */ - H5B__cache_serialize, /* 'serialize' callback */ - NULL, /* 'notify' callback */ - H5B__cache_free_icr, /* 'free_icr' callback */ - NULL, /* 'fsf_size' callback */ + H5AC_BT_ID, /* Metadata client ID */ + "v1 B-tree", /* Metadata client name (for debugging) */ + H5FD_MEM_BTREE, /* File space memory type for client */ + H5AC__CLASS_NO_FLAGS_SET, /* Client class behavior flags */ + H5B__cache_get_initial_load_size, /* 'get_initial_load_size' callback */ + NULL, /* 'get_final_load_size' callback */ + NULL, /* 'verify_chksum' callback */ + H5B__cache_deserialize, /* 'deserialize' callback */ + H5B__cache_image_len, /* 'image_len' callback */ + NULL, /* 'pre_serialize' callback */ + H5B__cache_serialize, /* 'serialize' callback */ + NULL, /* 'notify' callback */ + H5B__cache_free_icr, /* 'free_icr' callback */ + NULL, /* 'fsf_size' callback */ }}; /*******************/ /* Local Variables */ /*******************/ - - /*------------------------------------------------------------------------- * Function: H5B__cache_get_initial_load_size * @@ -98,7 +89,6 @@ const H5AC_class_t H5AC_BT[1] = {{ * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol - * koziol@hdfgroup.org * May 18, 2010 * *------------------------------------------------------------------------- @@ -106,10 +96,10 @@ const H5AC_class_t H5AC_BT[1] = {{ static herr_t H5B__cache_get_initial_load_size(void *_udata, size_t *image_len) { - H5B_cache_ud_t *udata = (H5B_cache_ud_t *)_udata; /* User data for callback */ - H5B_shared_t *shared; /* Pointer to shared B-tree info */ + H5B_cache_ud_t *udata = (H5B_cache_ud_t *)_udata; /* User data for callback */ + H5B_shared_t * shared; /* Pointer to shared B-tree info */ - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_PACKAGE_NOERR /* Check arguments */ HDassert(udata); @@ -125,7 +115,6 @@ H5B__cache_get_initial_load_size(void *_udata, size_t *image_len) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5B__cache_get_initial_load_size() */ - /*------------------------------------------------------------------------- * Function: H5B__cache_deserialize * @@ -135,32 +124,31 @@ H5B__cache_get_initial_load_size(void *_udata, size_t *image_len) * Failure: NULL * * Programmer: Quincey Koziol - * koziol@hdfgroup.org * Mar 24, 2008 * *------------------------------------------------------------------------- */ static void * H5B__cache_deserialize(const void *_image, size_t H5_ATTR_UNUSED len, void *_udata, - hbool_t H5_ATTR_UNUSED *dirty) + hbool_t H5_ATTR_UNUSED *dirty) { - H5B_t *bt = NULL; /* Pointer to the deserialized B-tree node */ - H5B_cache_ud_t *udata = (H5B_cache_ud_t *)_udata; /* User data for callback */ - H5B_shared_t *shared; /* Pointer to shared B-tree info */ - const uint8_t *image = (const uint8_t *)_image; /* Pointer into image buffer */ - uint8_t *native; /* Pointer to native keys */ - unsigned u; /* Local index variable */ - H5B_t *ret_value = NULL; /* Return value */ + H5B_t * bt = NULL; /* Pointer to the deserialized B-tree node */ + H5B_cache_ud_t *udata = (H5B_cache_ud_t *)_udata; /* User data for callback */ + H5B_shared_t * shared; /* Pointer to shared B-tree info */ + const uint8_t * image = (const uint8_t *)_image; /* Pointer into image buffer */ + uint8_t * native; /* Pointer to native keys */ + unsigned u; /* Local index variable */ + H5B_t * ret_value = NULL; /* Return value */ - FUNC_ENTER_STATIC + FUNC_ENTER_PACKAGE /* check arguments */ HDassert(image); HDassert(udata); /* Allocate the B-tree node in memory */ - if(NULL == (bt = H5FL_MALLOC(H5B_t))) - HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "can't allocate B-tree struct") + if (NULL == (bt = H5FL_MALLOC(H5B_t))) + HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "can't allocate B-tree struct") HDmemset(&bt->cache_info, 0, sizeof(H5AC_info_t)); /* Set & increment the ref-counted "shared" B-tree information for the node */ @@ -172,26 +160,26 @@ H5B__cache_deserialize(const void *_image, size_t H5_ATTR_UNUSED len, void *_uda HDassert(shared); /* Allocate space for the native keys and child addresses */ - if(NULL == (bt->native = H5FL_BLK_MALLOC(native_block, shared->sizeof_keys))) - HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "can't allocate buffer for native keys") - if(NULL == (bt->child = H5FL_SEQ_MALLOC(haddr_t, (size_t)shared->two_k))) - HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "can't allocate buffer for child addresses") + if (NULL == (bt->native = H5FL_BLK_MALLOC(native_block, shared->sizeof_keys))) + HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "can't allocate buffer for native keys") + if (NULL == (bt->child = H5FL_SEQ_MALLOC(haddr_t, (size_t)shared->two_k))) + HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "can't allocate buffer for child addresses") /* magic number */ - if(HDmemcmp(image, H5B_MAGIC, (size_t)H5_SIZEOF_MAGIC)) - HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "wrong B-tree signature") + if (HDmemcmp(image, H5B_MAGIC, (size_t)H5_SIZEOF_MAGIC) != 0) + HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "wrong B-tree signature") image += H5_SIZEOF_MAGIC; /* node type and level */ - if(*image++ != (uint8_t)udata->type->id) - HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, NULL, "incorrect B-tree node type") + if (*image++ != (uint8_t)udata->type->id) + HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, NULL, "incorrect B-tree node type") bt->level = *image++; /* entries used */ UINT16DECODE(image, bt->nchildren); /* Check if bt->nchildren is greater than two_k */ - if(bt->nchildren > shared->two_k) + if (bt->nchildren > shared->two_k) HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "number of children is greater than maximum") /* sibling pointers */ @@ -200,9 +188,9 @@ H5B__cache_deserialize(const void *_image, size_t H5_ATTR_UNUSED len, void *_uda /* the child/key pairs */ native = bt->native; - for(u = 0; u < bt->nchildren; u++) { + for (u = 0; u < bt->nchildren; u++) { /* Decode native key value */ - if((udata->type->decode)(shared, image, native) < 0) + if ((udata->type->decode)(shared, image, native) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, NULL, "unable to decode key") image += shared->sizeof_rkey; native += udata->type->sizeof_nkey; @@ -212,9 +200,9 @@ H5B__cache_deserialize(const void *_image, size_t H5_ATTR_UNUSED len, void *_uda } /* end for */ /* Decode final key */ - if(bt->nchildren > 0) { + if (bt->nchildren > 0) { /* Decode native key value */ - if((udata->type->decode)(shared, image, native) < 0) + if ((udata->type->decode)(shared, image, native) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, NULL, "unable to decode key") } /* end if */ @@ -225,14 +213,13 @@ H5B__cache_deserialize(const void *_image, size_t H5_ATTR_UNUSED len, void *_uda ret_value = bt; done: - if(!ret_value && bt) - if(H5B__node_dest(bt) < 0) + if (!ret_value && bt) + if (H5B__node_dest(bt) < 0) HDONE_ERROR(H5E_BTREE, H5E_CANTFREE, NULL, "unable to destroy B-tree node") FUNC_LEAVE_NOAPI(ret_value) } /* end H5B__cache_deserialize() */ - /*------------------------------------------------------------------------- * Function: H5B__cache_image_len * @@ -241,7 +228,6 @@ done: * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol - * koziol@hdfgroup.org * May 20, 2010 * *------------------------------------------------------------------------- @@ -249,10 +235,10 @@ done: static herr_t H5B__cache_image_len(const void *_thing, size_t *image_len) { - const H5B_t *bt = (const H5B_t *)_thing; /* Pointer to the B-tree node */ - H5B_shared_t *shared; /* Pointer to shared B-tree info */ + const H5B_t * bt = (const H5B_t *)_thing; /* Pointer to the B-tree node */ + H5B_shared_t *shared; /* Pointer to shared B-tree info */ - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_PACKAGE_NOERR /* Check arguments */ HDassert(bt); @@ -268,7 +254,6 @@ H5B__cache_image_len(const void *_thing, size_t *image_len) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5B__cache_image_len() */ - /*------------------------------------------------------------------------- * Function: H5B__cache_serialize * @@ -277,23 +262,21 @@ H5B__cache_image_len(const void *_thing, size_t *image_len) * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol - * koziol@hdfgroup.org * Mar 24, 2008 * *------------------------------------------------------------------------- */ static herr_t -H5B__cache_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED len, - void *_thing) +H5B__cache_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED len, void *_thing) { - H5B_t *bt = (H5B_t *)_thing; /* Pointer to the B-tree node */ - H5B_shared_t *shared; /* Pointer to shared B-tree info */ - uint8_t *image = (uint8_t *)_image; /* Pointer into image buffer */ - uint8_t *native; /* Pointer to native keys */ - unsigned u; /* Local index counter */ - herr_t ret_value = SUCCEED; /* Return value */ + H5B_t * bt = (H5B_t *)_thing; /* Pointer to the B-tree node */ + H5B_shared_t *shared; /* Pointer to shared B-tree info */ + uint8_t * image = (uint8_t *)_image; /* Pointer into image buffer */ + uint8_t * native; /* Pointer to native keys */ + unsigned u; /* Local index counter */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_STATIC + FUNC_ENTER_PACKAGE /* check arguments */ HDassert(image); @@ -312,8 +295,8 @@ H5B__cache_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED len, *image++ = (uint8_t)shared->type->id; /* 2^8 limit: only 1 byte is used to store node level */ - if(bt->level >= HDpow(2, LEVEL_BITS)) - HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, FAIL, "unable to encode node level") + if (bt->level >= HDpow(2, LEVEL_BITS)) + HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, FAIL, "unable to encode node level") H5_CHECK_OVERFLOW(bt->level, unsigned, uint8_t); *image++ = (uint8_t)bt->level; @@ -327,9 +310,9 @@ H5B__cache_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED len, /* child keys and pointers */ native = bt->native; - for(u = 0; u < bt->nchildren; ++u) { + for (u = 0; u < bt->nchildren; ++u) { /* encode the key */ - if(shared->type->encode(shared, image, native) < 0) + if (shared->type->encode(shared, image, native) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, FAIL, "unable to encode B-tree key") image += shared->sizeof_rkey; native += shared->type->sizeof_nkey; @@ -337,9 +320,9 @@ H5B__cache_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED len, /* encode the child address */ H5F_addr_encode(f, &image, bt->child[u]); } /* end for */ - if(bt->nchildren > 0) { + if (bt->nchildren > 0) { /* Encode the final key */ - if(shared->type->encode(shared, image, native) < 0) + if (shared->type->encode(shared, image, native) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, FAIL, "unable to encode B-tree key") image += shared->sizeof_rkey; } /* end if */ @@ -354,7 +337,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5B__cache_serialize() */ - /*------------------------------------------------------------------------- * Function: H5B__cache_free_icr * @@ -363,7 +345,6 @@ done: * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol - * koziol@hdfgroup.org * Mar 26, 2008 * *------------------------------------------------------------------------- @@ -371,18 +352,17 @@ done: static herr_t H5B__cache_free_icr(void *thing) { - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_STATIC + FUNC_ENTER_PACKAGE /* Check arguments */ HDassert(thing); /* Destroy B-tree node */ - if(H5B__node_dest((H5B_t *)thing) < 0) + if (H5B__node_dest((H5B_t *)thing) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to destroy B-tree node") done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5B__cache_free_icr() */ - |