//-------------------------------------------------------------------------- // Function: IdComponent::decRefCount ///\brief Decrement reference counter for a given id. // Programmer Binh-Minh Ribler - May 2005 // Modification: // Added the check for ref counter to give a little more info // on why H5Idec_ref fails in some cases - BMR 5/19/2005 //-------------------------------------------------------------------------- void IdComponent::decRefCount(const hid_t obj_id) const { if (p_valid_id(obj_id)) if (H5Idec_ref(obj_id) < 0) if (H5Iget_ref(obj_id) <= 0) throw IdComponentException(inMemFunc("decRefCount"), "object ref count is 0 or negative"); else throw IdComponentException(inMemFunc("decRefCount"), "decrementing object ref count failed"); }
/* * Class: hdf_hdf5lib_H5 * Method: H5Idec_1ref * Signature: (J)I */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Idec_1ref (JNIEnv *env, jclass clss, jlong obj_id) { int retVal = -1; retVal = H5Idec_ref((hid_t)obj_id); if (retVal < 0) h5libraryError(env); return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Idec_1ref */
/* Free callback */ static herr_t test_rct_free(void *_obj) { test_rct_obj_t *obj = (test_rct_obj_t *)_obj; long rem_idx, i; herr_t ret; /* return value */ /* Mark this object as freed */ obj->nfrees++; obj->obj_list->nobjs_rem--; /* Check freeing and nobjs_rem */ if(!obj->freeing && (obj->obj_list->nobjs_rem > 0)) { /* Remove a random object from the list */ rem_idx = HDrandom() % obj->obj_list->nobjs_rem; /* Scan the list, finding the rem_idx'th object that has not been * freed */ for(i = 0; i < obj->obj_list->nobjs; i++) if(obj->obj_list->list[i].nfrees == 0) { if(rem_idx == 0) break; else rem_idx--; } /* end if */ if(i == obj->obj_list->nobjs) { ERROR("invalid obj_list"); goto out; } /* end if */ else { /* Remove the object. Mark as "freeing" so its own callback does * not free another object. */ obj->obj_list->list[i].freeing = TRUE; ret = H5Idec_ref(obj->obj_list->list[i].id); CHECK(ret, FAIL, "H5Idec_ref"); if(ret == FAIL) goto out; obj->obj_list->list[i].freeing = FALSE; } /* end else */ } /* end if */ /* Verify nobjs_rem is non-negative */ if(obj->obj_list->nobjs_rem < 0) { ERROR("invalid nobjs_rem"); goto out; } /* end if */ return 0; out: return -1; } /* end test_rct_free() */
/****if* H5If/h5idec_ref_c * NAME * h5idec_ref_c * PURPOSE * Call H5Idec_ref to decrement object's reference count * INPUTS * obj_id - object identifier * OUTPUTS * ref_count - Reference count of ID * RETURNS * current reference count on success, -1 on failure * AUTHOR * Quincey Koziol * Tuesday, December 9, 2003 * SOURCE */ int_f h5idec_ref_c(hid_t_f *obj_id, int_f *ref_count) /******/ { int ret_value; /* * Call H5Idec_ref function */ if ((ret_value = H5Idec_ref(*obj_id)) < 0) HGOTO_DONE(FAIL); /* Set output & return values */ *ref_count=ret_value; ret_value=0; done: return ret_value; }