summaryrefslogtreecommitdiffstats
path: root/src/H5I.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-09-16 14:15:13 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-09-16 14:15:13 (GMT)
commit9f028ea4589cfd21ce610050c75895ed69b2ee08 (patch)
tree9eea3e34c3604d6506d6b2d3ee9af6244e659ec0 /src/H5I.c
parent6fb5f819a51f27ffc44b21e2d0e44808ba71da17 (diff)
downloadhdf5-9f028ea4589cfd21ce610050c75895ed69b2ee08.zip
hdf5-9f028ea4589cfd21ce610050c75895ed69b2ee08.tar.gz
hdf5-9f028ea4589cfd21ce610050c75895ed69b2ee08.tar.bz2
[svn-r19399] Description:
Bring r19398 from trunk to 1.8 branch: 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/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
Diffstat (limited to 'src/H5I.c')
-rw-r--r--src/H5I.c302
1 files changed, 125 insertions, 177 deletions
diff --git a/src/H5I.c b/src/H5I.c
index 01dab4e..6fb13d2 100644
--- a/src/H5I.c
+++ b/src/H5I.c
@@ -172,9 +172,7 @@ H5I_init_interface(void)
*
* Failure: Negative.
*
- * Programmer:
- *
- * Modifications:
+ * Programmer: Unknown
*
*-------------------------------------------------------------------------
*/
@@ -224,15 +222,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
@@ -270,22 +265,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
@@ -394,15 +376,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
@@ -433,19 +412,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
@@ -495,8 +467,6 @@ done:
* Programmer: Robb Matzke
* Wednesday, March 24, 1999
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
int
@@ -528,14 +498,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
@@ -563,7 +531,6 @@ done:
* function for each object regardless of the reference count.
*
* Return: Success: Non-negative
- *
* Failure: negative
*
* Programmer: Robb Matzke
@@ -727,8 +694,6 @@ done:
* Programmer: Nathaniel Furrer
* James Laird
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
herr_t
@@ -762,8 +727,6 @@ done:
* Programmer: Nathaniel Furrer
* James Laird
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
herr_t
@@ -801,13 +764,10 @@ done:
* Purpose: Public interface to H5I_register.
*
* Return: Success: New object id.
- *
* Failure: Negative
*
* Programmer: Nathaniel Furrer
- * James Laird
- *
- * Modifications:
+ * James Laird
*
*-------------------------------------------------------------------------
*/
@@ -841,7 +801,6 @@ done:
* the ID which is returned to the user.
*
* Return: Success: New object id.
- *
* Failure: Negative
*
* Programmer: Unknown
@@ -1016,12 +975,9 @@ done:
*
* Return: Success: Non-null object pointer associated with the
* specified ID.
- *
* Failure: NULL
*
- * Programmer:
- *
- * Modifications:
+ * Programmer: Unknown
*
*-------------------------------------------------------------------------
*/
@@ -1054,15 +1010,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 *
@@ -1093,14 +1046,11 @@ done:
*
* Return: Success: Non-null object pointer associated with the
* specified ID.
- *
* Failure: NULL
*
* Programmer: Quincey Koziol
* Wednesday, July 31, 2002
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
void *
@@ -1134,14 +1084,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
@@ -1170,15 +1117,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
@@ -1209,13 +1151,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
*
*-------------------------------------------------------------------------
*/
@@ -1246,13 +1185,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
*
*-------------------------------------------------------------------------
*/
@@ -1283,12 +1219,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
*
*-------------------------------------------------------------------------
*/
@@ -1403,7 +1336,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:
@@ -1426,41 +1359,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 */
@@ -1481,7 +1383,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")
/*
@@ -1494,10 +1396,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) */
@@ -1505,19 +1407,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)
@@ -1525,6 +1421,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.
@@ -1535,8 +1524,6 @@ done:
* Programmer: Quincey Koziol
* Dec 7, 2003
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
int
@@ -1566,7 +1553,6 @@ done:
* Purpose: Increment the reference count for an object.
*
* Return: Success: The new reference count.
- *
* Failure: Negative
*
* Programmer: Robb Matzke
@@ -1630,8 +1616,6 @@ done:
* Programmer: Quincey Koziol
* Dec 7, 2003
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
int
@@ -1661,7 +1645,6 @@ done:
* Purpose: Retrieve the reference count for an object.
*
* Return: Success: The reference count.
- *
* Failure: Negative
*
* Programmer: Quincey Koziol
@@ -1718,11 +1701,9 @@ done:
* Failure: Negative
*
* Programmer: Nat Furrer
- * James Laird
+ * James Laird
* April 30, 2004
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
int
@@ -1755,15 +1736,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
@@ -1808,9 +1786,7 @@ done:
* Return: Number of references to type on success/Negative on failure
*
* Programmer: Nathaniel Furrer
- * James Laird
- *
- * Modifications:
+ * James Laird
*
*-------------------------------------------------------------------------
*/
@@ -1850,11 +1826,6 @@ done:
*
* Programmer: Unknown
*
- * Modifications:
- *
- * Robb Matzke, 25 Feb 1998
- * IDs are freed when a type is destroyed.
- *
*-------------------------------------------------------------------------
*/
herr_t
@@ -1901,11 +1872,9 @@ done:
* Failure: Negative
*
* Programmer: Nat Furrer
- * James Laird
+ * James Laird
* April 30, 2004
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
int
@@ -1942,11 +1911,9 @@ done:
* Failure: Negative
*
* Programmer: Nat Furrer
- * James Laird
+ * James Laird
* April 30, 2004
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
int
@@ -1986,12 +1953,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
@@ -2072,7 +2033,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
@@ -2135,12 +2095,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 *
@@ -2252,8 +2208,6 @@ done:
* Programmer: Raymond Lu
* Oct 27, 2003
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
hid_t
@@ -2324,21 +2278,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
*
*-------------------------------------------------------------------------
*/