diff options
Diffstat (limited to 'src/H5FSsection.c')
-rw-r--r-- | src/H5FSsection.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/H5FSsection.c b/src/H5FSsection.c index 26ff7b9..30885a9 100644 --- a/src/H5FSsection.c +++ b/src/H5FSsection.c @@ -1562,6 +1562,71 @@ done: /*------------------------------------------------------------------------- + * Function: H5FS_sect_try_merge + * + * Purpose: Try to merge/shrink a block + * + * Return: TRUE: merged/shrunk + * FALSE: not merged/not shrunk + * Failure: negative + * + * Programmer: Vailin Choi; June 10, 2009 + * + *------------------------------------------------------------------------- + */ +htri_t +H5FS_sect_try_merge(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace, H5FS_section_info_t *sect, + unsigned flags, void *op_data) +{ + hbool_t sinfo_valid = FALSE; /* Whether the section info is valid */ + hbool_t sinfo_modified = FALSE; /* Whether the section info was modified */ + hsize_t saved_fs_size; /* copy the free-space section size */ + htri_t ret_value = FALSE; /* Return value */ + + FUNC_ENTER_NOAPI(H5FS_sect_try_merge, FAIL) + + /* Check arguments. */ + HDassert(f); + HDassert(fspace); + HDassert(sect); + HDassert(H5F_addr_defined(sect->addr)); + HDassert(sect->size); + + /* Get a pointer to the section info */ + if(H5FS_sinfo_lock(f, dxpl_id, fspace, H5AC_WRITE) < 0) + HGOTO_ERROR(H5E_FSPACE, H5E_CANTGET, FAIL, "can't get section info") + sinfo_valid = TRUE; + saved_fs_size = sect->size; + + /* Attempt to merge/shrink section with existing sections */ + if(H5FS_sect_merge(fspace, §, op_data) < 0) + HGOTO_ERROR(H5E_FSPACE, H5E_CANTMERGE, FAIL, "can't merge sections") + + /* Check if section is shrunk and/or merged away completely */ + if(!sect) { + sinfo_modified = TRUE; + HGOTO_DONE(TRUE) + } /* end if */ + else { + /* Check if section is merged */ + if(sect->size > saved_fs_size) { + if(H5FS_sect_link(fspace, sect, flags) < 0) + HGOTO_ERROR(H5E_FSPACE, H5E_CANTINSERT, FAIL, "can't insert free space section into skip list") + sinfo_modified = TRUE; + HGOTO_DONE(TRUE) + } /* end if */ + } /* end else */ + +done: + /* Release the section info */ + if(sinfo_valid && H5FS_sinfo_unlock(f, dxpl_id, fspace, sinfo_modified) < 0) + HDONE_ERROR(H5E_FSPACE, H5E_CANTRELEASE, FAIL, "can't release section info") + + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FS_sect_try_merge() */ + + +/*------------------------------------------------------------------------- * Function: H5FS_sect_find_node * * Purpose: Locate a section of free space (in existing free space list |