diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2020-10-01 14:04:36 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2020-10-01 14:04:36 (GMT) |
commit | f1ba03cea5b82699a984c80bd2deac14fdc8df18 (patch) | |
tree | ebe777c3e0b83f4c4cec9212731da9ebe0a0cfd3 /src/H5Fefc.c | |
parent | 10343c197906415388f2a4c8d292e21d25cf7381 (diff) | |
download | hdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.zip hdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.tar.gz hdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.tar.bz2 |
Source formatted
Diffstat (limited to 'src/H5Fefc.c')
-rw-r--r-- | src/H5Fefc.c | 343 |
1 files changed, 165 insertions, 178 deletions
diff --git a/src/H5Fefc.c b/src/H5Fefc.c index c9a3a00..c1f94d7 100644 --- a/src/H5Fefc.c +++ b/src/H5Fefc.c @@ -24,56 +24,54 @@ *------------------------------------------------------------------------- */ -#include "H5Fmodule.h" /* This source code file is part of the H5F module */ - +#include "H5Fmodule.h" /* This source code file is part of the H5F module */ /* Packages needed by this file... */ -#include "H5private.h" /* Generic Functions */ -#include "H5CXprivate.h" /* API Contexts */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5Fpkg.h" /* File access */ -#include "H5Iprivate.h" /* IDs */ -#include "H5MMprivate.h" /* Memory management */ -#include "H5Pprivate.h" /* Property lists */ +#include "H5private.h" /* Generic Functions */ +#include "H5CXprivate.h" /* API Contexts */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Fpkg.h" /* File access */ +#include "H5Iprivate.h" /* IDs */ +#include "H5MMprivate.h" /* Memory management */ +#include "H5Pprivate.h" /* Property lists */ /* Special values for the "tag" field below */ -#define H5F_EFC_TAG_DEFAULT -1 -#define H5F_EFC_TAG_LOCK -2 -#define H5F_EFC_TAG_CLOSE -3 -#define H5F_EFC_TAG_DONTCLOSE -4 +#define H5F_EFC_TAG_DEFAULT -1 +#define H5F_EFC_TAG_LOCK -2 +#define H5F_EFC_TAG_CLOSE -3 +#define H5F_EFC_TAG_DONTCLOSE -4 /* Structure for each entry in a file's external file cache */ typedef struct H5F_efc_ent_t { - char *name; /* Name of the file */ - H5F_t *file; /* File object */ - struct H5F_efc_ent_t *LRU_next; /* Next item in LRU list */ - struct H5F_efc_ent_t *LRU_prev; /* Previous item in LRU list */ - unsigned nopen; /* Number of times this file is currently opened by an EFC client */ + char * name; /* Name of the file */ + H5F_t * file; /* File object */ + struct H5F_efc_ent_t *LRU_next; /* Next item in LRU list */ + struct H5F_efc_ent_t *LRU_prev; /* Previous item in LRU list */ + unsigned nopen; /* Number of times this file is currently opened by an EFC client */ } H5F_efc_ent_t; /* Structure for a shared file struct's external file cache */ struct H5F_efc_t { - H5SL_t *slist; /* Skip list of cached external files */ - H5F_efc_ent_t *LRU_head; /* Head of LRU list. This is the least recently used file */ - H5F_efc_ent_t *LRU_tail; /* Tail of LRU list. This is the most recently used file */ - unsigned nfiles; /* Size of the external file cache */ - unsigned max_nfiles; /* Maximum size of the external file cache */ - unsigned nrefs; /* Number of times this file appears in another file's EFC */ - int tag; /* Temporary variable used by H5F__efc_try_close() */ - H5F_shared_t *tmp_next; /* Next file in temporary list used by H5F__efc_try_close() */ + H5SL_t * slist; /* Skip list of cached external files */ + H5F_efc_ent_t *LRU_head; /* Head of LRU list. This is the least recently used file */ + H5F_efc_ent_t *LRU_tail; /* Tail of LRU list. This is the most recently used file */ + unsigned nfiles; /* Size of the external file cache */ + unsigned max_nfiles; /* Maximum size of the external file cache */ + unsigned nrefs; /* Number of times this file appears in another file's EFC */ + int tag; /* Temporary variable used by H5F__efc_try_close() */ + H5F_shared_t * tmp_next; /* Next file in temporary list used by H5F__efc_try_close() */ }; /* Private prototypes */ static herr_t H5F__efc_release_real(H5F_efc_t *efc); static herr_t H5F__efc_remove_ent(H5F_efc_t *efc, H5F_efc_ent_t *ent); -static void H5F__efc_try_close_tag1(H5F_shared_t *sf, H5F_shared_t **tail); -static void H5F__efc_try_close_tag2(H5F_shared_t *sf, H5F_shared_t **tail); +static void H5F__efc_try_close_tag1(H5F_shared_t *sf, H5F_shared_t **tail); +static void H5F__efc_try_close_tag2(H5F_shared_t *sf, H5F_shared_t **tail); /* Free lists */ H5FL_DEFINE_STATIC(H5F_efc_ent_t); H5FL_DEFINE_STATIC(H5F_efc_t); - /*------------------------------------------------------------------------- * Function: H5F__efc_create * @@ -92,8 +90,8 @@ H5FL_DEFINE_STATIC(H5F_efc_t); H5F_efc_t * H5F__efc_create(unsigned max_nfiles) { - H5F_efc_t *efc = NULL; /* EFC object */ - H5F_efc_t *ret_value = NULL; /* Return value */ + H5F_efc_t *efc = NULL; /* EFC object */ + H5F_efc_t *ret_value = NULL; /* Return value */ FUNC_ENTER_PACKAGE @@ -101,7 +99,7 @@ H5F__efc_create(unsigned max_nfiles) HDassert(max_nfiles > 0); /* Allocate EFC struct */ - if(NULL == (efc = H5FL_CALLOC(H5F_efc_t))) + if (NULL == (efc = H5FL_CALLOC(H5F_efc_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Initialize maximum number of files */ @@ -114,13 +112,12 @@ H5F__efc_create(unsigned max_nfiles) ret_value = efc; done: - if(ret_value == NULL && efc) + if (ret_value == NULL && efc) efc = H5FL_FREE(H5F_efc_t, efc); FUNC_LEAVE_NOAPI(ret_value) } /* end H5F__efc_create() */ - /*------------------------------------------------------------------------- * Function: H5F__efc_open * @@ -143,12 +140,12 @@ done: H5F_t * H5F__efc_open(H5F_t *parent, const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id) { - H5F_efc_t *efc = NULL; /* External file cache for parent file */ - H5F_efc_ent_t *ent = NULL; /* Entry for target file in efc */ - hbool_t open_file = FALSE; /* Whether ent->file needs to be closed in case of error */ - H5P_genplist_t *plist; /* Property list pointer for FAPL */ - H5VL_connector_prop_t connector_prop; /* Property for VOL connector ID & info */ - H5F_t *ret_value = NULL; /* Return value */ + H5F_efc_t * efc = NULL; /* External file cache for parent file */ + H5F_efc_ent_t * ent = NULL; /* Entry for target file in efc */ + hbool_t open_file = FALSE; /* Whether ent->file needs to be closed in case of error */ + H5P_genplist_t * plist; /* Property list pointer for FAPL */ + H5VL_connector_prop_t connector_prop; /* Property for VOL connector ID & info */ + H5F_t * ret_value = NULL; /* Return value */ FUNC_ENTER_PACKAGE @@ -158,15 +155,15 @@ H5F__efc_open(H5F_t *parent, const char *name, unsigned flags, hid_t fcpl_id, hi HDassert(name); /* Get the VOL info from the fapl */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id))) + if (NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id))) HGOTO_ERROR(H5E_FILE, H5E_BADTYPE, NULL, "not a file access property list") - if(H5P_peek(plist, H5F_ACS_VOL_CONN_NAME, &connector_prop) < 0) + if (H5P_peek(plist, H5F_ACS_VOL_CONN_NAME, &connector_prop) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "can't get VOL connector info") /* Stash a copy of the "top-level" connector property, before any pass-through * connectors modify or unwrap it. */ - if(H5CX_set_vol_connector_prop(&connector_prop) < 0) + if (H5CX_set_vol_connector_prop(&connector_prop) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTSET, NULL, "can't set VOL connector info in API context") /* Get external file cache */ @@ -175,12 +172,12 @@ H5F__efc_open(H5F_t *parent, const char *name, unsigned flags, hid_t fcpl_id, hi /* Check if the EFC exists. If it does not, just call H5F_open(). We * support this so clients do not have to make 2 different calls depending * on the state of the efc. */ - if(!efc) { - if(NULL == (ret_value = H5F_open(name, flags, fcpl_id, fapl_id))) + if (!efc) { + if (NULL == (ret_value = H5F_open(name, flags, fcpl_id, fapl_id))) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "can't open file") /* Make file post open call */ - if(H5F__post_open(ret_value) < 0) + if (H5F__post_open(ret_value) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "can't finish opening file") /* Increment the number of open objects to prevent the file from being @@ -194,31 +191,31 @@ H5F__efc_open(H5F_t *parent, const char *name, unsigned flags, hid_t fcpl_id, hi /* Search the skip list for name if the skip list exists, create the skip * list otherwise */ - if(efc->slist) { - if(efc->nfiles > 0) + if (efc->slist) { + if (efc->nfiles > 0) ent = (H5F_efc_ent_t *)H5SL_search(efc->slist, name); } /* end if */ else { HDassert(efc->nfiles == 0); - if(NULL == (efc->slist = H5SL_create(H5SL_TYPE_STR, NULL))) + if (NULL == (efc->slist = H5SL_create(H5SL_TYPE_STR, NULL))) HGOTO_ERROR(H5E_FILE, H5E_CANTCREATE, NULL, "can't create skip list") } /* end else */ /* If we found the file update the LRU list and return the cached file, * otherwise open the file and cache it */ - if(ent) { + if (ent) { HDassert(efc->LRU_head); HDassert(efc->LRU_tail); /* Move ent to the head of the LRU list, if it is not already there */ - if(ent->LRU_prev) { + if (ent->LRU_prev) { HDassert(efc->LRU_head != ent); /* Remove from current position. Note that once we touch the LRU * list we cannot revert to the previous state. Make sure there can * be no errors between when we first touch the LRU list and when * the cache is in a consistent state! */ - if(ent->LRU_next) + if (ent->LRU_next) ent->LRU_next->LRU_prev = ent->LRU_prev; else { HDassert(efc->LRU_tail == ent); @@ -227,10 +224,10 @@ H5F__efc_open(H5F_t *parent, const char *name, unsigned flags, hid_t fcpl_id, hi ent->LRU_prev->LRU_next = ent->LRU_next; /* Add to head of LRU list */ - ent->LRU_next = efc->LRU_head; + ent->LRU_next = efc->LRU_head; ent->LRU_next->LRU_prev = ent; - ent->LRU_prev = NULL; - efc->LRU_head = ent; + ent->LRU_prev = NULL; + efc->LRU_head = ent; } /* end if */ /* Mark the file as open */ @@ -238,25 +235,26 @@ H5F__efc_open(H5F_t *parent, const char *name, unsigned flags, hid_t fcpl_id, hi } /* end if */ else { /* Check if we need to evict something */ - if(efc->nfiles == efc->max_nfiles) { + if (efc->nfiles == efc->max_nfiles) { /* Search for an unopened file from the tail */ - for(ent = efc->LRU_tail; ent && ent->nopen; ent = ent->LRU_prev); + for (ent = efc->LRU_tail; ent && ent->nopen; ent = ent->LRU_prev) + ; /* Evict the file if found, otherwise just open the target file and * do not add it to cache */ - if(ent) { - if(H5F__efc_remove_ent(efc, ent) < 0) + if (ent) { + if (H5F__efc_remove_ent(efc, ent) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTREMOVE, NULL, "can't remove entry from external file cache") /* Do not free ent, we will recycle it below */ } /* end if */ else { /* Cannot cache file, just open file and return */ - if(NULL == (ret_value = H5F_open(name, flags, fcpl_id, fapl_id))) + if (NULL == (ret_value = H5F_open(name, flags, fcpl_id, fapl_id))) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "can't open file") /* Make file post open call */ - if(H5F__post_open(ret_value) < 0) + if (H5F__post_open(ret_value) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "can't finish opening file") /* Increment the number of open objects to prevent the file from @@ -266,23 +264,23 @@ H5F__efc_open(H5F_t *parent, const char *name, unsigned flags, hid_t fcpl_id, hi HGOTO_DONE(ret_value) } /* end else */ - } /* end if */ + } /* end if */ else /* Allocate new entry */ - if(NULL == (ent = H5FL_MALLOC(H5F_efc_ent_t))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + if (NULL == (ent = H5FL_MALLOC(H5F_efc_ent_t))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Build new entry */ - if(NULL == (ent->name = H5MM_strdup(name))) + if (NULL == (ent->name = H5MM_strdup(name))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Open the file */ - if(NULL == (ent->file = H5F_open(name, flags, fcpl_id, fapl_id))) + if (NULL == (ent->file = H5F_open(name, flags, fcpl_id, fapl_id))) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "can't open file") open_file = TRUE; /* Make file post open call */ - if(H5F__post_open(ent->file) < 0) + if (H5F__post_open(ent->file) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "can't finish opening file") /* Increment the number of open objects to prevent the file from being @@ -291,16 +289,16 @@ H5F__efc_open(H5F_t *parent, const char *name, unsigned flags, hid_t fcpl_id, hi /* Add the file to the cache */ /* Skip list */ - if(H5SL_insert(efc->slist, ent, ent->name) < 0) + if (H5SL_insert(efc->slist, ent, ent->name) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTINSERT, NULL, "can't insert entry into skip list") /* Add to head of LRU list and update tail if necessary */ ent->LRU_next = efc->LRU_head; - if(ent->LRU_next) + if (ent->LRU_next) ent->LRU_next->LRU_prev = ent; ent->LRU_prev = NULL; efc->LRU_head = ent; - if(!efc->LRU_tail) { + if (!efc->LRU_tail) { HDassert(!ent->LRU_next); efc->LRU_tail = ent; } /* end if */ @@ -310,7 +308,7 @@ H5F__efc_open(H5F_t *parent, const char *name, unsigned flags, hid_t fcpl_id, hi /* Update nfiles and nrefs */ efc->nfiles++; - if(ent->file->shared->efc) + if (ent->file->shared->efc) ent->file->shared->efc->nrefs++; } /* end else */ @@ -323,21 +321,20 @@ H5F__efc_open(H5F_t *parent, const char *name, unsigned flags, hid_t fcpl_id, hi ret_value = ent->file; done: - if(!ret_value) - if(ent) { - if(open_file) { + if (!ret_value) + if (ent) { + if (open_file) { ent->file->nopen_objs--; - if(H5F_try_close(ent->file, NULL) < 0) + if (H5F_try_close(ent->file, NULL) < 0) HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, NULL, "can't close external file") } /* end if */ ent->name = (char *)H5MM_xfree(ent->name); - ent = H5FL_FREE(H5F_efc_ent_t, ent); + ent = H5FL_FREE(H5F_efc_ent_t, ent); } /* end if */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5F__efc_open() */ - /*------------------------------------------------------------------------- * Function: H5F_efc_close * @@ -356,9 +353,9 @@ done: herr_t H5F_efc_close(H5F_t *parent, H5F_t *file) { - H5F_efc_t *efc = NULL; /* External file cache for parent file */ - H5F_efc_ent_t *ent = NULL; /* Entry for target file in efc */ - herr_t ret_value = SUCCEED; /* Return value */ + H5F_efc_t * efc = NULL; /* External file cache for parent file */ + H5F_efc_ent_t *ent = NULL; /* Entry for target file in efc */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -374,9 +371,9 @@ H5F_efc_close(H5F_t *parent, H5F_t *file) /* Check if the EFC exists. If it does not, just call H5F_try_close(). We * support this so clients do not have to make 2 different calls depending * on the state of the efc. */ - if(!efc) { + if (!efc) { file->nopen_objs--; - if(H5F_try_close(file, NULL) < 0) + if (H5F_try_close(file, NULL) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "can't close external file") HGOTO_DONE(SUCCEED) @@ -387,10 +384,11 @@ H5F_efc_close(H5F_t *parent, H5F_t *file) * the head. In the unlikely case that the file is not found, just call * H5F_try_close(). This could happen if the EFC was full of open files * when the file was opened. */ - for(ent = efc->LRU_head; ent && ent->file != file; ent = ent->LRU_next); - if(!ent) { + for (ent = efc->LRU_head; ent && ent->file != file; ent = ent->LRU_next) + ; + if (!ent) { file->nopen_objs--; - if(H5F_try_close(file, NULL) < 0) + if (H5F_try_close(file, NULL) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "can't close external file") } /* end if */ else @@ -401,7 +399,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5F_efc_close() */ - /*------------------------------------------------------------------------- * Function: H5F__efc_max_nfiles * @@ -426,7 +423,6 @@ H5F__efc_max_nfiles(H5F_efc_t *efc) FUNC_LEAVE_NOAPI(efc->max_nfiles) } /* end H5F__efc_max_nfiles */ - /*------------------------------------------------------------------------- * Function: H5F__efc_release_real * @@ -445,9 +441,9 @@ H5F__efc_max_nfiles(H5F_efc_t *efc) static herr_t H5F__efc_release_real(H5F_efc_t *efc) { - H5F_efc_ent_t *ent = NULL; /* EFC entry */ - H5F_efc_ent_t *prev_ent = NULL; /* Previous EFC entry */ - herr_t ret_value = SUCCEED; /* Return value */ + H5F_efc_ent_t *ent = NULL; /* EFC entry */ + H5F_efc_ent_t *prev_ent = NULL; /* Previous EFC entry */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -459,21 +455,20 @@ H5F__efc_release_real(H5F_efc_t *efc) * would require a cycle, a cycle would necessarily invoke * H5F__efc_try_close(), and that function checks the status of the lock * before calling this one. */ - HDassert((efc->tag == H5F_EFC_TAG_DEFAULT) - || (efc->tag == H5F_EFC_TAG_CLOSE)); + HDassert((efc->tag == H5F_EFC_TAG_DEFAULT) || (efc->tag == H5F_EFC_TAG_CLOSE)); efc->tag = H5F_EFC_TAG_LOCK; /* Walk down the LRU list, releasing any files that are not opened by an EFC * client */ ent = efc->LRU_head; - while(ent) - if(!ent->nopen) { - if(H5F__efc_remove_ent(efc, ent) < 0) + while (ent) + if (!ent->nopen) { + if (H5F__efc_remove_ent(efc, ent) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTREMOVE, FAIL, "can't remove entry from external file cache") /* Free the entry and move to next entry in LRU list */ prev_ent = ent; - ent = ent->LRU_next; + ent = ent->LRU_next; prev_ent = H5FL_FREE(H5F_efc_ent_t, prev_ent); } /* end if */ else @@ -488,7 +483,6 @@ done: FUNC_LEAVE_NOAPI(ret_value); } /* end H5F__efc_release_real() */ - /*------------------------------------------------------------------------- * Function: H5F__efc_release * @@ -507,7 +501,7 @@ done: herr_t H5F__efc_release(H5F_efc_t *efc) { - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -515,14 +509,13 @@ H5F__efc_release(H5F_efc_t *efc) HDassert(efc); /* Call 'real' routine */ - if(H5F__efc_release_real(efc) < 0) + if (H5F__efc_release_real(efc) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTRELEASE, FAIL, "can't remove entry from external file cache") done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5F_efc_release() */ - /*------------------------------------------------------------------------- * Function: H5F__efc_destroy * @@ -541,20 +534,20 @@ done: herr_t H5F__efc_destroy(H5F_efc_t *efc) { - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE /* Sanity checks */ HDassert(efc); - if(efc->nfiles > 0) { + if (efc->nfiles > 0) { /* Release (clear) the efc */ - if(H5F__efc_release_real(efc) < 0) + if (H5F__efc_release_real(efc) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTRELEASE, FAIL, "can't release external file cache") /* If there are still cached files, return an error */ - if(efc->nfiles > 0) + if (efc->nfiles > 0) HGOTO_ERROR(H5E_FILE, H5E_CANTFREE, FAIL, "can't destroy EFC after incomplete release") } /* end if */ @@ -563,8 +556,8 @@ H5F__efc_destroy(H5F_efc_t *efc) HDassert(efc->LRU_tail == NULL); /* Close skip list */ - if(efc->slist) - if(H5SL_close(efc->slist) < 0) + if (efc->slist) + if (H5SL_close(efc->slist) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTFREE, FAIL, "can't close skip list") /* Free EFC object */ @@ -574,7 +567,6 @@ done: FUNC_LEAVE_NOAPI(ret_value); } /* end H5F__efc_destroy() */ - /*------------------------------------------------------------------------- * Function: H5F__efc_remove_ent * @@ -592,7 +584,7 @@ done: static herr_t H5F__efc_remove_ent(H5F_efc_t *efc, H5F_efc_ent_t *ent) { - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -602,17 +594,17 @@ H5F__efc_remove_ent(H5F_efc_t *efc, H5F_efc_ent_t *ent) HDassert(ent); /* Remove from skip list */ - if(ent != H5SL_remove(efc->slist, ent->name)) + if (ent != H5SL_remove(efc->slist, ent->name)) HGOTO_ERROR(H5E_FILE, H5E_CANTDELETE, FAIL, "can't delete entry from skip list") /* Remove from LRU list */ - if(ent->LRU_next) + if (ent->LRU_next) ent->LRU_next->LRU_prev = ent->LRU_prev; else { HDassert(efc->LRU_tail == ent); efc->LRU_tail = ent->LRU_prev; } /* end else */ - if(ent->LRU_prev) + if (ent->LRU_prev) ent->LRU_prev->LRU_next = ent->LRU_next; else { HDassert(efc->LRU_head == ent); @@ -621,7 +613,7 @@ H5F__efc_remove_ent(H5F_efc_t *efc, H5F_efc_ent_t *ent) /* Update nfiles and nrefs */ efc->nfiles--; - if(ent->file->shared->efc) + if (ent->file->shared->efc) ent->file->shared->efc->nrefs--; /* Free the name */ @@ -632,7 +624,7 @@ H5F__efc_remove_ent(H5F_efc_t *efc, H5F_efc_ent_t *ent) * However we must still manipulate the nopen_objs field to prevent the file * from being closed out from under us. */ ent->file->nopen_objs--; - if(H5F_try_close(ent->file, NULL) < 0) + if (H5F_try_close(ent->file, NULL) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "can't close external file") ent->file = NULL; @@ -640,7 +632,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5F__efc_remove_ent() */ - /*------------------------------------------------------------------------- * Function: H5F__efc_try_close_tag1 * @@ -658,8 +649,8 @@ done: static void H5F__efc_try_close_tag1(H5F_shared_t *sf, H5F_shared_t **tail) { - H5F_efc_ent_t *ent = NULL; /* EFC entry */ - H5F_shared_t *esf; /* Convenience pointer to ent->file->shared */ + H5F_efc_ent_t *ent = NULL; /* EFC entry */ + H5F_shared_t * esf; /* Convenience pointer to ent->file->shared */ FUNC_ENTER_STATIC_NOERR @@ -672,17 +663,17 @@ H5F__efc_try_close_tag1(H5F_shared_t *sf, H5F_shared_t **tail) HDassert(*tail); /* Recurse into this file's cached files */ - for(ent = sf->efc->LRU_head; ent; ent = ent->LRU_next) { + for (ent = sf->efc->LRU_head; ent; ent = ent->LRU_next) { esf = ent->file->shared; - if(esf->efc) { + if (esf->efc) { /* If tag were 0, that would mean there are more actual references * than are counted by nrefs */ HDassert(esf->efc->tag != 0); /* If tag has been set, we have already visited this file so just * decrement tag and continue */ - if(esf->efc->tag > 0) + if (esf->efc->tag > 0) esf->efc->tag--; /* If there are references that are not from an EFC, it will never * be possible to close the file. Just continue. Also continue if @@ -690,8 +681,8 @@ H5F__efc_try_close_tag1(H5F_shared_t *sf, H5F_shared_t **tail) * that the reference counts will never match for the root file, but * that's ok because the root file will always have a tag and enter * the branch above. */ - else if((esf->nrefs == esf->efc->nrefs) - && (esf->efc->tag != H5F_EFC_TAG_LOCK) && !(ent->nopen)) { + else if ((esf->nrefs == esf->efc->nrefs) && (esf->efc->tag != H5F_EFC_TAG_LOCK) && + !(ent->nopen)) { /* If we get here, this file's "tmp_next" pointer must be NULL */ HDassert(esf->efc->tmp_next == NULL); @@ -699,22 +690,21 @@ H5F__efc_try_close_tag1(H5F_shared_t *sf, H5F_shared_t **tail) /* If nrefs > 1, Add this file to the list of files with nrefs > * 1 and initialize tag to the number of references (except this * one) */ - if(esf->nrefs > 1) { + if (esf->nrefs > 1) { (*tail)->efc->tmp_next = esf; - *tail = esf; - esf->efc->tag = (int)esf->nrefs - 1; + *tail = esf; + esf->efc->tag = (int)esf->nrefs - 1; } /* end if */ /* Recurse into the entry */ H5F__efc_try_close_tag1(ent->file->shared, tail); } /* end if */ - } /* end if */ - } /* end for */ + } /* end if */ + } /* end for */ FUNC_LEAVE_NOAPI_VOID } /* end H5F__efc_try_close_tag1() */ - /*------------------------------------------------------------------------- * Function: H5F__efc_try_close_tag2 * @@ -732,8 +722,8 @@ H5F__efc_try_close_tag1(H5F_shared_t *sf, H5F_shared_t **tail) static void H5F__efc_try_close_tag2(H5F_shared_t *sf, H5F_shared_t **tail) { - H5F_efc_ent_t *ent = NULL; /* EFC entry */ - H5F_shared_t *esf; /* Convenience pointer to ent->file->shared */ + H5F_efc_ent_t *ent = NULL; /* EFC entry */ + H5F_shared_t * esf; /* Convenience pointer to ent->file->shared */ FUNC_ENTER_STATIC_NOERR @@ -742,7 +732,7 @@ H5F__efc_try_close_tag2(H5F_shared_t *sf, H5F_shared_t **tail) HDassert(sf->efc); /* Recurse into this file's cached files */ - for(ent = sf->efc->LRU_head; ent; ent = ent->LRU_next) { + for (ent = sf->efc->LRU_head; ent; ent = ent->LRU_next) { esf = ent->file->shared; /* Only recurse if the file is tagged CLOSE or DEFAULT. If it is tagged @@ -753,39 +743,36 @@ H5F__efc_try_close_tag2(H5F_shared_t *sf, H5F_shared_t **tail) * make sure we do not go off into somewhere cb1 didn't touch. The * root file should never be tagged DEFAULT here, so the reference check * is still appropriate. */ - if((esf->efc) && ((esf->efc->tag == H5F_EFC_TAG_CLOSE) - || ((esf->efc->tag == H5F_EFC_TAG_DEFAULT) - && (esf->nrefs == esf->efc->nrefs) && !(ent->nopen)))) { + if ((esf->efc) && + ((esf->efc->tag == H5F_EFC_TAG_CLOSE) || + ((esf->efc->tag == H5F_EFC_TAG_DEFAULT) && (esf->nrefs == esf->efc->nrefs) && !(ent->nopen)))) { /* tag should always be CLOSE is nrefs > 1 or DEFAULT if nrefs == 1 * here */ - HDassert(((esf->nrefs > 1) - && ((esf->efc->tag == H5F_EFC_TAG_CLOSE))) - || ((esf->nrefs == 1) - && (esf->efc->tag == H5F_EFC_TAG_DEFAULT))); + HDassert(((esf->nrefs > 1) && ((esf->efc->tag == H5F_EFC_TAG_CLOSE))) || + ((esf->nrefs == 1) && (esf->efc->tag == H5F_EFC_TAG_DEFAULT))); /* If tag is set to DONTCLOSE, we have already visited this file * *or* it will be the start point of another iteration so just * continue */ - if(esf->efc->tag != H5F_EFC_TAG_DONTCLOSE) { + if (esf->efc->tag != H5F_EFC_TAG_DONTCLOSE) { /* If tag is CLOSE, set to DONTCLOSE and add to the list of * uncloseable files. */ - if(esf->efc->tag == H5F_EFC_TAG_CLOSE) { - esf->efc->tag = H5F_EFC_TAG_DONTCLOSE; - esf->efc->tmp_next = NULL; + if (esf->efc->tag == H5F_EFC_TAG_CLOSE) { + esf->efc->tag = H5F_EFC_TAG_DONTCLOSE; + esf->efc->tmp_next = NULL; (*tail)->efc->tmp_next = esf; - *tail = esf; + *tail = esf; } /* end if */ /* Recurse into the entry */ H5F__efc_try_close_tag2(esf, tail); } /* end if */ - } /* end if */ - } /* end for */ + } /* end if */ + } /* end for */ FUNC_LEAVE_NOAPI_VOID } /* end H5F__efc_try_close_tag2() */ - /*------------------------------------------------------------------------- * Function: H5F__efc_try_close * @@ -839,12 +826,14 @@ H5F__efc_try_close_tag2(H5F_shared_t *sf, H5F_shared_t **tail) herr_t H5F__efc_try_close(H5F_t *f) { - H5F_shared_t *tail; /* Tail of linked list of found files. Head will be f->shared. */ - H5F_shared_t *uncloseable_head = NULL; /* Head of linked list of files found to be uncloseable by the first pass */ - H5F_shared_t *uncloseable_tail = NULL; /* Tail of linked list of files found to be uncloseable by the first pass */ - H5F_shared_t *sf; /* Temporary file pointer */ - H5F_shared_t *next; /* Temporary file pointer */ - herr_t ret_value = SUCCEED; /* Return value */ + H5F_shared_t *tail; /* Tail of linked list of found files. Head will be f->shared. */ + H5F_shared_t *uncloseable_head = + NULL; /* Head of linked list of files found to be uncloseable by the first pass */ + H5F_shared_t *uncloseable_tail = + NULL; /* Tail of linked list of files found to be uncloseable by the first pass */ + H5F_shared_t *sf; /* Temporary file pointer */ + H5F_shared_t *next; /* Temporary file pointer */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -856,12 +845,12 @@ H5F__efc_try_close(H5F_t *f) HDassert(f->shared->nrefs > 1); HDassert(f->shared->efc->tag < 0); - if(f->shared->efc->tag == H5F_EFC_TAG_CLOSE) { + if (f->shared->efc->tag == H5F_EFC_TAG_CLOSE) { /* We must have reentered this function, and we should close this file. * In actuality, we just release the EFC, the recursion should * eventually reduce this file's reference count to 1 (though possibly * not from this call to H5F__efc_release_real()). */ - if(H5F__efc_release_real(f->shared->efc) < 0) + if (H5F__efc_release_real(f->shared->efc) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTRELEASE, FAIL, "can't release external file cache") /* If we marked the file as closeable, there must be no open files in @@ -887,9 +876,8 @@ H5F__efc_try_close(H5F_t *f) * not close/release it */ /* If nfiles is 0, then there is nothing to do. Just return. This may also * occur on reentry (for example if this file was previously released). */ - if((f->shared->nrefs != f->shared->efc->nrefs + 1) - || (f->shared->efc->tag == H5F_EFC_TAG_DONTCLOSE) - || (f->shared->efc->nfiles == 0)) + if ((f->shared->nrefs != f->shared->efc->nrefs + 1) || (f->shared->efc->tag == H5F_EFC_TAG_DONTCLOSE) || + (f->shared->efc->nfiles == 0)) /* We must have reentered this function, and we should not close this * file. Just return. */ HGOTO_DONE(SUCCEED) @@ -917,13 +905,13 @@ H5F__efc_try_close(H5F_t *f) /* Check if f->shared->efc->tag dropped to 0. If it did not, * we cannot close anything. Just reset temporary values and return. */ - if(f->shared->efc->tag > 0) { + if (f->shared->efc->tag > 0) { sf = f->shared; - while(sf) { - next = sf->efc->tmp_next; - sf->efc->tag = H5F_EFC_TAG_DEFAULT; + while (sf) { + next = sf->efc->tmp_next; + sf->efc->tag = H5F_EFC_TAG_DEFAULT; sf->efc->tmp_next = NULL; - sf = next; + sf = next; } /* end while */ HGOTO_DONE(SUCCEED) } /* end if */ @@ -931,19 +919,19 @@ H5F__efc_try_close(H5F_t *f) /* Run through the linked list , separating into two lists, one with tag == * 0 and one with tag > 0. Mark them as either H5F_EFC_TAG_CLOSE or * H5F_EFC_TAG_DONTCLOSE as appropriate. */ - sf = f->shared; + sf = f->shared; tail = NULL; - while(sf) { + while (sf) { HDassert(sf->efc->tag >= 0); next = sf->efc->tmp_next; - if(sf->efc->tag > 0) { + if (sf->efc->tag > 0) { /* Remove from main list */ HDassert(tail); tail->efc->tmp_next = sf->efc->tmp_next; - sf->efc->tmp_next = NULL; + sf->efc->tmp_next = NULL; /* Add to uncloseable list */ - if(!uncloseable_head) + if (!uncloseable_head) uncloseable_head = sf; else uncloseable_tail->efc->tmp_next = sf; @@ -954,7 +942,7 @@ H5F__efc_try_close(H5F_t *f) } /* end if */ else { sf->efc->tag = H5F_EFC_TAG_CLOSE; - tail = sf; + tail = sf; } /* end else */ sf = next; } /* end while */ @@ -967,20 +955,20 @@ H5F__efc_try_close(H5F_t *f) * so we know when to stop. We do not need to keep track of the closeable * list any more. */ sf = uncloseable_head; - if(sf) { + if (sf) { tail = uncloseable_tail; HDassert(tail); - while(sf != tail->efc->tmp_next) { + while (sf != tail->efc->tmp_next) { H5F__efc_try_close_tag2(sf, &uncloseable_tail); sf = sf->efc->tmp_next; } /* end while */ - } /* end if */ + } /* end if */ /* If the root file's tag is still H5F_EFC_TAG_CLOSE, release its EFC. This * should start the recursive release that should close all closeable files. * Also, see the top of this function. */ - if(f->shared->efc->tag == H5F_EFC_TAG_CLOSE) { - if(H5F__efc_release_real(f->shared->efc) < 0) + if (f->shared->efc->tag == H5F_EFC_TAG_CLOSE) { + if (H5F__efc_release_real(f->shared->efc) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTRELEASE, FAIL, "can't release external file cache") /* Make sure the file's reference count is now 1 and will be closed by @@ -990,18 +978,17 @@ H5F__efc_try_close(H5F_t *f) /* Clean up uncloseable files (reset tag and tmp_next). All closeable files * should have been closed, and therefore do not need to be cleaned up. */ - if(uncloseable_head) { + if (uncloseable_head) { sf = uncloseable_head; - while(sf) { + while (sf) { next = sf->efc->tmp_next; HDassert(sf->efc->tag == H5F_EFC_TAG_DONTCLOSE); - sf->efc->tag = H5F_EFC_TAG_DEFAULT; + sf->efc->tag = H5F_EFC_TAG_DEFAULT; sf->efc->tmp_next = NULL; - sf = next; + sf = next; } /* end while */ - } /* end if */ + } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5F__efc_try_close() */ - |