diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2010-09-16 14:02:19 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2010-09-16 14:02:19 (GMT) |
commit | 1914737e0658d642c1ef2e48c6162fa7cc400c64 (patch) | |
tree | d514c5e86096148b10b67f5e178dce87a7625d4d /src/H5I.c | |
parent | e5575571d4faaee78c67fc7dbae7d8229b1bfb94 (diff) | |
download | hdf5-1914737e0658d642c1ef2e48c6162fa7cc400c64.zip hdf5-1914737e0658d642c1ef2e48c6162fa7cc400c64.tar.gz hdf5-1914737e0658d642c1ef2e48c6162fa7cc400c64.tar.bz2 |
[svn-r19398] Descriptino:
Clean up the internal usage H5I_dec_ref() to eliminate the sequence of
flags that has been creeping in.
Tested on:
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x,
w/C++ & FORTRAN, w/threadsafe, in debug mode
Linux/64-amd64 2.6 (amani) w/Intel compilers, w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, w/threadsafe, in production mode
Linux/PPC 2.6 (heiwa) w/C++ & FORTRAN, w/threadsafe, in debug mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in debug mode
Mac OS X/32 10.6.4 (amazon) in debug mode
Mac OS X/32 10.6.4 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
Mac OS X/32 10.6.4 (amazon) w/parallel, in debug mode
Diffstat (limited to 'src/H5I.c')
-rw-r--r-- | src/H5I.c | 302 |
1 files changed, 125 insertions, 177 deletions
@@ -165,9 +165,7 @@ H5I_init_interface(void) * * Failure: Negative. * - * Programmer: - * - * Modifications: + * Programmer: Unknown * *------------------------------------------------------------------------- */ @@ -217,15 +215,12 @@ H5I_term_interface(void) * the type. * * Return: Success: Type ID of the new type - * * Failure: H5I_BADID * * Programmers: Nathaniel Furrer - * James Laird + * James Laird * Friday, April 30, 2004 * - * Modifications: - * *------------------------------------------------------------------------- */ H5I_type_t @@ -263,22 +258,9 @@ done: * Failure: H5I_BADID * * Programmers: Nathaniel Furrer - * James Laird + * James Laird * Friday, April 30, 2004 * - * Modifications: The initialization section of this function was formerly - * H5I_init_type, programmed by Robb Matzke on February 19, - * 1999. - * - * Bill Wendling, 2000-05-05 - * Instead of the ugly test of whether hash_size is a power of - * two, I placed it in a macro POWER_OF_TWO which uses the fact - * that a number that is a power of two has only 1 bit set. - * - * Bill Wendling, 2000-05-09 - * Changed POWER_OF_TWO macro to allow 1 as a valid power of two. - * Changed test below accordingly. - * *------------------------------------------------------------------------- */ H5I_type_t @@ -376,15 +358,12 @@ done: * currently registered with the library. * * Return: Success: 1 if the type is registered, 0 if it is not - * * Failure: Negative * * Programmer: James Laird * Nathaniel Furrer * Tuesday, June 29, 2004 * - * Modifications: - * *------------------------------------------------------------------------- */ htri_t @@ -415,19 +394,12 @@ done: * private interface, which will just return 0. * * Return: Success: Zero - * * Failure: Negative * * Programmer: James Laird * Nathaniel Furrer * Friday, April 23, 2004 * - * Modifications: - * June 29, 2004 - * Nat Furrer and James Laird - * Changed function signature to return the number of members - * by reference. - * *------------------------------------------------------------------------- */ herr_t @@ -477,8 +449,6 @@ done: * Programmer: Robb Matzke * Wednesday, March 24, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ int @@ -510,14 +480,12 @@ done: * Public interface to H5I_clear_type. * * Return: Success: Non-negative - * * Failure: negative * * Programmer: James Laird - * Nathaniel Furrer + * Nathaniel Furrer * Friday, April 23, 2004 * - * Modifications: *------------------------------------------------------------------------- */ herr_t @@ -545,7 +513,6 @@ done: * function for each object regardless of the reference count. * * Return: Success: Non-negative - * * Failure: negative * * Programmer: Robb Matzke @@ -699,8 +666,6 @@ done: * Programmer: Nathaniel Furrer * James Laird * - * Modifications: - * *------------------------------------------------------------------------- */ herr_t @@ -734,8 +699,6 @@ done: * Programmer: Nathaniel Furrer * James Laird * - * Modifications: - * *------------------------------------------------------------------------- */ herr_t @@ -773,13 +736,10 @@ done: * Purpose: Public interface to H5I_register. * * Return: Success: New object id. - * * Failure: Negative * * Programmer: Nathaniel Furrer - * James Laird - * - * Modifications: + * James Laird * *------------------------------------------------------------------------- */ @@ -813,7 +773,6 @@ done: * the ID which is returned to the user. * * Return: Success: New object id. - * * Failure: Negative * * Programmer: Unknown @@ -969,12 +928,9 @@ done: * * Return: Success: Non-null object pointer associated with the * specified ID. - * * Failure: NULL * - * Programmer: - * - * Modifications: + * Programmer: Unknown * *------------------------------------------------------------------------- */ @@ -1007,15 +963,12 @@ done: * * Return: Success: Non-null object pointer associated with the * specified ID. - * * Failure: NULL * * Programmer: Nathaniel Furrer * James Laird * Friday, April 23, 2004 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -1046,14 +999,11 @@ done: * * Return: Success: Non-null object pointer associated with the * specified ID. - * * Failure: NULL * * Programmer: Quincey Koziol * Wednesday, July 31, 2002 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -1087,14 +1037,11 @@ done: * in the object ID. * * Return: Success: A valid type number - * * Failure: H5I_BADID, a negative value. * * Programmer: Robb Matzke * Friday, February 19, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ H5I_type_t @@ -1123,15 +1070,10 @@ done: * encoded as part of the ID. * * Return: Success: Type number - * * Failure: H5I_BADID, a negative value * - * Programmer: + * Programmer: Unknown * - * Modifications: - * Robb Matzke, 1999-08-23 - * Also fails if the ID has a valid type but no longer exists - * in the ID tables. *------------------------------------------------------------------------- */ H5I_type_t @@ -1162,13 +1104,10 @@ done: * Return: Success: A pointer to the object that was removed, the * same pointer which would have been found by * calling H5I_object(). - * * Failure: NULL * * Programmer: James Laird - * Nathaniel Furrer - * - * Modifications: + * Nathaniel Furrer * *------------------------------------------------------------------------- */ @@ -1199,13 +1138,10 @@ done: * Return: Success: A pointer to the object that was removed, the * same pointer which would have been found by * calling H5I_object(). - * * Failure: NULL * * Programmer: James Laird - * Nat Furrer - * - * Modifications: + * Nat Furrer * *------------------------------------------------------------------------- */ @@ -1236,12 +1172,9 @@ done: * Return: Success: A pointer to the object that was removed, the * same pointer which would have been found by * calling H5I_object(). - * * Failure: NULL * - * Programmer: - * - * Modifications: + * Programmer: Unknown * *------------------------------------------------------------------------- */ @@ -1330,7 +1263,7 @@ H5Idec_ref(hid_t id) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "invalid ID") /* Do actual decrement operation */ - if((ret_value = H5I_dec_ref(id, TRUE, FALSE)) < 0) + if((ret_value = H5I_dec_app_ref(id)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTDEC, FAIL, "can't decrement ID ref count") done: @@ -1353,41 +1286,10 @@ done: * * Programmer: Unknown * - * Modifications: - * - * Robb Matzke, 19 Feb 1998 - * It is no longer an error when the reference count of an item reaches - * zero and no `free' function has been defined. The object is still - * removed from the list. - * - * Robb Matzke, 30 Dec 1998 - * Fixed a bug where the return value was always zero instead of the new - * reference count. - * - * Robb Matzke, 19 Feb 1999 - * If the free method is defined and fails then the object is not - * removed from the type and its reference count is not decremented. - * The type number is now passed to the free method. - * - * Raymond Lu, 11 Dec 2001 - * If the freeing function fails, return failure instead of reference - * count 1. This feature is needed by file close with H5F_CLOSE_SEMI - * value. - * - * Neil Fortner, 7 Aug 2008 - * Added app_ref parameter and support for the app_count field, to - * distiguish between reference count from the library and from the - * application. - * - * Raymond Lu, 7 September 2010 - * I added the 3rd parameter to indicate whether H5Dclose is calling - * this function. All other calls should pass in FALSE. Please see - * the comments in the code below. - * *------------------------------------------------------------------------- */ int -H5I_dec_ref(hid_t id, hbool_t app_ref, hbool_t dset_close) +H5I_dec_ref(hid_t id) { H5I_type_t type; /*type the object is in*/ H5I_id_type_t *type_ptr; /*ptr to the type */ @@ -1408,7 +1310,7 @@ H5I_dec_ref(hid_t id, hbool_t app_ref, hbool_t dset_close) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "invalid type number") /* General lookup of the ID */ - if(NULL == (id_ptr=H5I_find_id(id))) + if(NULL == (id_ptr = H5I_find_id(id))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't locate ID") /* @@ -1421,10 +1323,10 @@ H5I_dec_ref(hid_t id, hbool_t app_ref, hbool_t dset_close) * * Beware: the free method may call other H5I functions. * - * If a dataset is closing, we remove the ID even though the freeing - * might fail. This can happen when a mandatory filter fails to write - * when the dataset is closed and the chunk cache is flushed to the - * file. We have a close the dataset anyway. (SLU - 2010/9/7) + * If an object is closing, we can remove the ID even though the free + * method might fail. This can happen when a mandatory filter fails to + * write when a dataset is closed and the chunk cache is flushed to the + * file. We have to close the dataset anyway. (SLU - 2010/9/7) */ if(1 == id_ptr->count) { /* (Casting away const OK -QAK) */ @@ -1432,19 +1334,13 @@ H5I_dec_ref(hid_t id, hbool_t app_ref, hbool_t dset_close) H5I_remove(id); ret_value = 0; } /* end if */ - else { - if(dset_close) - H5I_remove(id); + else ret_value = FAIL; - } } /* end if */ else { --(id_ptr->count); - if(app_ref) - --(id_ptr->app_count); - HDassert(id_ptr->count >= id_ptr->app_count); - ret_value = (int)(app_ref ? id_ptr->app_count : id_ptr->count); - } + ret_value = (int)id_ptr->count; + } /* end else */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -1452,6 +1348,99 @@ done: /*------------------------------------------------------------------------- + * Function: H5I_dec_app_ref + * + * Purpose: H5I_dec_ref wrapper for case of modifying the application ref. + * count for an ID as well as normal reference count. + * + * Return: Success: New app. reference count. + * Failure: Negative + * + * Programmer: Quincey Koziol + * Sept 16, 2010 + * + *------------------------------------------------------------------------- + */ +int +H5I_dec_app_ref(hid_t id) +{ + H5I_id_info_t *id_ptr; /*ptr to the new ID */ + int ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5I_dec_app_ref, FAIL) + + /* Sanity check */ + HDassert(id >= 0); + + /* Call regular decrement reference count routine */ + if((ret_value = H5I_dec_ref(id)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTDEC, FAIL, "can't decrement ID ref count") + + /* Check if the ID still exists */ + if(ret_value > 0) { + /* General lookup of the ID */ + if(NULL == (id_ptr = H5I_find_id(id))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't locate ID") + + /* Adjust app_ref */ + --(id_ptr->app_count); + HDassert(id_ptr->count >= id_ptr->app_count); + + /* Set return value */ + ret_value = (int)id_ptr->app_count; + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5I_dec_app_ref() */ + + +/*------------------------------------------------------------------------- + * Function: H5I_dec_app_ref_always_close + * + * Purpose: H5I_dec_app_ref wrapper for case of always closing the ID, + * even when the free routine fails + * + * Return: Success: New app. reference count. + * Failure: Negative + * + * Programmer: Quincey Koziol + * Sept 16, 2010 + * + *------------------------------------------------------------------------- + */ +int +H5I_dec_app_ref_always_close(hid_t id) +{ + int ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5I_dec_app_ref_always_close, FAIL) + + /* Sanity check */ + HDassert(id >= 0); + + /* Call application decrement reference count routine */ + ret_value = H5I_dec_app_ref(id); + + /* Check for failure */ + if(ret_value < 0) { + /* + * If an object is closing, we can remove the ID even though the free + * method might fail. This can happen when a mandatory filter fails to + * write when a dataset is closed and the chunk cache is flushed to the + * file. We have to close the dataset anyway. (SLU - 2010/9/7) + */ + H5I_remove(id); + + HGOTO_ERROR(H5E_ATOM, H5E_CANTDEC, FAIL, "can't decrement ID ref count") + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5I_dec_app_ref_always_close() */ + + +/*------------------------------------------------------------------------- * Function: H5Iinc_ref * * Purpose: Increments the number of references outstanding for an ID. @@ -1462,8 +1451,6 @@ done: * Programmer: Quincey Koziol * Dec 7, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ int @@ -1493,7 +1480,6 @@ done: * Purpose: Increment the reference count for an object. * * Return: Success: The new reference count. - * * Failure: Negative * * Programmer: Robb Matzke @@ -1557,8 +1543,6 @@ done: * Programmer: Quincey Koziol * Dec 7, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ int @@ -1588,7 +1572,6 @@ done: * Purpose: Retrieve the reference count for an object. * * Return: Success: The reference count. - * * Failure: Negative * * Programmer: Quincey Koziol @@ -1645,11 +1628,9 @@ done: * Failure: Negative * * Programmer: Nat Furrer - * James Laird + * James Laird * April 30, 2004 * - * Modifications: - * *------------------------------------------------------------------------- */ int @@ -1682,15 +1663,12 @@ done: * Purpose: Increment the reference count for an ID type. * * Return: Success: The new reference count. - * * Failure: Negative * * Programmer: James Laird - * Nat Furrer + * Nat Furrer * Friday, April 30, 2004 * - * Modifications: - * *------------------------------------------------------------------------- */ int @@ -1735,9 +1713,7 @@ done: * Return: Number of references to type on success/Negative on failure * * Programmer: Nathaniel Furrer - * James Laird - * - * Modifications: + * James Laird * *------------------------------------------------------------------------- */ @@ -1777,11 +1753,6 @@ done: * * Programmer: Unknown * - * Modifications: - * - * Robb Matzke, 25 Feb 1998 - * IDs are freed when a type is destroyed. - * *------------------------------------------------------------------------- */ herr_t @@ -1828,11 +1799,9 @@ done: * Failure: Negative * * Programmer: Nat Furrer - * James Laird + * James Laird * April 30, 2004 * - * Modifications: - * *------------------------------------------------------------------------- */ int @@ -1869,11 +1838,9 @@ done: * Failure: Negative * * Programmer: Nat Furrer - * James Laird + * James Laird * April 30, 2004 * - * Modifications: - * *------------------------------------------------------------------------- */ int @@ -1913,12 +1880,6 @@ done: * Programmer: Neil Fortner * Friday, October 31, 2008 (boo) * - * Modifications: - * Raymond Lu - * 1 April 2009 (Believe it or not!) - * Moved the argument check down to H5I_find_id because other - * caller functions may pass in some invalid IDs to H5I_find_id. - * It used to do assertion check. *------------------------------------------------------------------------- */ htri_t @@ -1999,7 +1960,6 @@ done: * Return: Success: The first object in the type for which FUNC * returns non-zero. NULL if FUNC returned zero * for every object in the type. - * * Failure: NULL * * Programmer: Robb Matzke @@ -2062,12 +2022,8 @@ done: * * Failure: NULL * - * Programmer: + * Programmer: Unknown * - * Modifications: - * Raymond Lu - * 1 April 2009 (Believe it or not!) - * Added argument check, took away assertion check. *------------------------------------------------------------------------- */ static H5I_id_info_t * @@ -2179,8 +2135,6 @@ done: * Programmer: Raymond Lu * Oct 27, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ hid_t @@ -2251,21 +2205,15 @@ done: /*------------------------------------------------------------------------- - * Function: H5I_debug - * - * Purpose: Dump the contents of a type to stderr for debugging. + * Function: H5I_debug * - * Return: Success: Non-negative + * Purpose: Dump the contents of a type to stderr for debugging. * - * Failure: Negative + * Return: Success: Non-negative + * Failure: Negative * - * Programmer: Robb Matzke - * Friday, February 19, 1999 - * - * Modifications: - * - * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002 - * Added `id to name' support. + * Programmer: Robb Matzke + * Friday, February 19, 1999 * *------------------------------------------------------------------------- */ |