[svn-r7801] Purpose: added feature

Description:  more feature to H5Iget_file_id().  If file ID is closed, it can
still return an ID given object ID.


Platforms tested: h5committest
This commit is contained in:
Raymond Lu 2003-10-31 13:48:35 -05:00
parent 7ef1503d40
commit 7948d9eb26
4 changed files with 44 additions and 8 deletions

View File

@ -2217,6 +2217,9 @@ H5Fopen(const char *filename, unsigned flags, hid_t fapl_id)
if ((ret_value = H5I_register(H5I_FILE, new_file))<0)
HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle")
/* Keep this ID in file object structure */
new_file->file_id = ret_value;
done:
if (ret_value<0 && new_file)
if(H5F_close(new_file)<0)
@ -3219,6 +3222,10 @@ H5F_close(H5F_t *f)
/* Register an ID for closing the file later */
if (!f->closing)
f->closing = H5I_register(H5I_FILE_CLOSING, f);
/* Invalidate file ID */
f->file_id = -1;
HGOTO_DONE(SUCCEED)
} else {
if (f->closing) {
@ -3249,6 +3256,10 @@ H5F_close(H5F_t *f)
/* Register an ID for closing the file later */
if (!f->closing)
f->closing = H5I_register(H5I_FILE_CLOSING, f);
/* Invalidate file ID */
f->file_id = -1;
HGOTO_DONE(SUCCEED)
} else {
if (!f->closing && f->shared->nrefs>1)
@ -3260,7 +3271,7 @@ H5F_close(H5F_t *f)
break;
case H5F_CLOSE_STRONG:
/* Forcefully close all opened objects in file */
/* Force to close all opened objects in file */
while(f->nopen_objs > 0) {
int obj_count; /* # of open objects */
hid_t objs[128]; /* Array of objects to close */
@ -3311,6 +3322,9 @@ H5F_close(H5F_t *f)
HGOTO_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "can't close file, unknown file close degree")
} /* end switch */
/* Invalidate file ID */
f->file_id = -1;
/* Only flush at this point if the file will be closed */
assert(closing);
/* Dump debugging info */
@ -3931,6 +3945,9 @@ H5Freopen(hid_t file_id)
if ((ret_value=H5I_register(H5I_FILE, new_file))<0)
HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle")
/* Keep this ID in file object structure */
new_file->file_id = ret_value;
done:
if (ret_value<0 && new_file)
if(H5F_close(new_file)<0)
@ -4189,8 +4206,25 @@ H5F_get_id(H5F_t *file)
FUNC_ENTER_NOINIT(H5F_get_id)
assert(file);
if(file->file_id == -1) {
if(H5I_remove(file->closing)==NULL)
HGOTO_ERROR(H5E_ATOM, H5E_READERROR, FAIL, "unable to remove from closing list")
/* Get an atom for the file */
if ((file->file_id = H5I_register(H5I_FILE, file))<0)
HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file")
/* Indicate file is not closing */
file->closing = 0;
} else {
/* Increment reference count on atom. */
if (H5I_inc_ref(file->file_id)<0)
HGOTO_ERROR (H5E_ATOM, H5E_CANTSET, FAIL, "incrementing file ID failed");
}
ret_value = file->file_id;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_get_id() */

View File

@ -38,6 +38,7 @@
#include "H5private.h" /* Generic Functions */
#include "H5Bprivate.h" /* B-trees */
#include "H5Fprivate.h" /* File access */
#include "H5Gprivate.h" /* Group */
#include "H5RSprivate.h" /* Reference-counted strings */
/*

View File

@ -117,7 +117,6 @@ H5FL_DEFINE_STATIC(H5I_id_info_t);
/*--------------------- Local function prototypes ---------------------------*/
static herr_t H5I_init_interface(void);
static H5I_id_info_t *H5I_find_id(hid_t id);
static hid_t H5I_get_file_id(hid_t obj_id);
#ifdef H5I_DEBUG_OUTPUT
static herr_t H5I_debug(H5I_type_t grp);
#endif /* H5I_DEBUG_OUTPUT */
@ -843,7 +842,7 @@ done:
*
*-------------------------------------------------------------------------
*/
static hid_t
hid_t
H5I_get_file_id(hid_t obj_id)
{
H5G_entry_t *ent;
@ -855,6 +854,11 @@ H5I_get_file_id(hid_t obj_id)
switch(H5I_GRP(obj_id)) {
case H5I_FILE:
ret_value = obj_id;
/* Increment reference count on atom. */
if (H5I_inc_ref(ret_value)<0)
HGOTO_ERROR (H5E_ATOM, H5E_CANTSET, FAIL, "incrementing file ID failed");
break;
case H5I_DATATYPE:
@ -875,10 +879,6 @@ H5I_get_file_id(hid_t obj_id)
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "invalid object ID");
}
/* Increment reference count on atom. */
if (H5I_inc_ref(ret_value)<0)
HGOTO_ERROR (H5E_ATOM, H5E_CANTSET, FAIL, "incrementing file ID failed");
done:
FUNC_LEAVE_NOAPI(ret_value);
}

View File

@ -67,6 +67,7 @@ H5_DLL hid_t H5I_register(H5I_type_t grp, void *object);
H5_DLL void *H5I_object(hid_t id);
H5_DLL void *H5I_object_verify(hid_t id, H5I_type_t id_type);
H5_DLL H5I_type_t H5I_get_type(hid_t id);
H5_DLL hid_t H5I_get_file_id(hid_t obj_id);
H5_DLL void *H5I_remove(hid_t id);
H5_DLL void *H5I_search(H5I_type_t grp, H5I_search_func_t func, void *key);
H5_DLL int H5I_inc_ref(hid_t id);