diff options
author | Quincey Koziol <koziol@lbl.gov> | 2020-12-01 19:20:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-01 19:20:05 (GMT) |
commit | 3e61010340b7b545f434e3b39dbb56337f8803b5 (patch) | |
tree | db16a6276a41cfa9d6f8c7be0d74f2b02dff038d /src/H5Iint.c | |
parent | adf7b1d4cf788f25a52619f5d1c957ac5a7c345c (diff) | |
download | hdf5-3e61010340b7b545f434e3b39dbb56337f8803b5.zip hdf5-3e61010340b7b545f434e3b39dbb56337f8803b5.tar.gz hdf5-3e61010340b7b545f434e3b39dbb56337f8803b5.tar.bz2 |
Expand ID dec_ref and close callbacks to allow for asynchronous close operations (#135)
* Expand ID dec_ref and close callbacks to allow for asynchronous close operations.
* Fix typo
* Rename token -> request, remove programmer name
* H5E_ATOM to H5E_ID
Diffstat (limited to 'src/H5Iint.c')
-rw-r--r-- | src/H5Iint.c | 138 |
1 files changed, 118 insertions, 20 deletions
diff --git a/src/H5Iint.c b/src/H5Iint.c index 95baa28..b511cb5 100644 --- a/src/H5Iint.c +++ b/src/H5Iint.c @@ -77,6 +77,9 @@ typedef struct { static void * H5I__unwrap(void *object, H5I_type_t type); static htri_t H5I__clear_type_cb(void *_id, void *key, void *udata); static void * H5I__remove_common(H5I_type_info_t *type_info, hid_t id); +static int H5I__dec_ref(hid_t id, void **request); +static int H5I__dec_app_ref(hid_t id, void **request); +static int H5I__dec_app_ref_always_close(hid_t id, void **request); static int H5I__find_id_cb(void *_item, void *_key, void *_udata); /*********************/ @@ -367,7 +370,7 @@ H5I__clear_type_cb(void *_info, void H5_ATTR_UNUSED *key, void *_udata) /* Check for a 'free' function and call it, if it exists */ H5_GCC_DIAG_OFF("cast-qual") if (udata->type_info->cls->free_func && - (udata->type_info->cls->free_func)((void *)info->object) < 0) { /* (Casting away const OK -QAK) */ + (udata->type_info->cls->free_func)((void *)info->object, H5_REQUEST_NULL) < 0) { /* (Casting away const OK -QAK) */ if (udata->force) { #ifdef H5I_DEBUG if (H5DEBUG(I)) { @@ -887,7 +890,7 @@ done: } /* end H5I_remove() */ /*------------------------------------------------------------------------- - * Function: H5I_dec_ref + * Function: H5I__dec_ref * * Purpose: Decrements the number of references outstanding for an ID. * This will fail if the type is not a reference counted type. @@ -895,18 +898,21 @@ done: * if the reference count for the ID reaches 0 and a free * function has been defined at type creation time. * + * Note: Allows for asynchronous 'close' operation on object, with + * request != H5_REQUEST_NULL. + * * Return: Success: New reference count * Failure: -1 * *------------------------------------------------------------------------- */ -int -H5I_dec_ref(hid_t id) +static int +H5I__dec_ref(hid_t id, void **request) { H5I_id_info_t *info = NULL; /* Pointer to the ID */ int ret_value = 0; /* Return value */ - FUNC_ENTER_NOAPI((-1)) + FUNC_ENTER_STATIC /* Sanity check */ HDassert(id >= 0); @@ -937,7 +943,7 @@ H5I_dec_ref(hid_t id) H5_GCC_DIAG_OFF("cast-qual") /* (Casting away const OK -QAK) */ - if (!type_info->cls->free_func || (type_info->cls->free_func)((void *)info->object) >= 0) { + if (!type_info->cls->free_func || (type_info->cls->free_func)((void *)info->object, request) >= 0) { /* Remove the node from the type */ if (NULL == H5I__remove_common(type_info, id)) HGOTO_ERROR(H5E_ID, H5E_CANTDELETE, (-1), "can't remove ID node") @@ -954,34 +960,62 @@ H5I_dec_ref(hid_t id) done: FUNC_LEAVE_NOAPI(ret_value) +} /* end H5I__dec_ref */ + +/*------------------------------------------------------------------------- + * Function: H5I_dec_ref + * + * Purpose: Decrements the number of references outstanding for an ID. + * + * Return: Success: New reference count + * Failure: -1 + * + *------------------------------------------------------------------------- + */ +int +H5I_dec_ref(hid_t id) +{ + int ret_value = 0; /* Return value */ + + FUNC_ENTER_NOAPI((-1)) + + /* Sanity check */ + HDassert(id >= 0); + + /* Synchronously decrement refcount on ID */ + if ((ret_value = H5I__dec_ref(id, H5_REQUEST_NULL)) < 0) + HGOTO_ERROR(H5E_ID, H5E_CANTDEC, (-1), "can't decrement ID ref count") + +done: + FUNC_LEAVE_NOAPI(ret_value) } /* end H5I_dec_ref() */ /*------------------------------------------------------------------------- - * Function: H5I_dec_app_ref + * Function: H5I__dec_app_ref * * Purpose: Wrapper for case of modifying the application ref. * count for an ID as well as normal reference count. * + * Note: Allows for asynchronous 'close' operation on object, with + * request != H5_REQUEST_NULL. + * * Return: Success: New app. reference count * Failure: -1 * - * Programmer: Quincey Koziol - * Sept 16, 2010 - * *------------------------------------------------------------------------- */ -int -H5I_dec_app_ref(hid_t id) +static int +H5I__dec_app_ref(hid_t id, void **request) { int ret_value = 0; /* Return value */ - FUNC_ENTER_NOAPI((-1)) + FUNC_ENTER_STATIC /* Sanity check */ HDassert(id >= 0); /* Call regular decrement reference count routine */ - if ((ret_value = H5I_dec_ref(id)) < 0) + if ((ret_value = H5I__dec_ref(id, request)) < 0) HGOTO_ERROR(H5E_ID, H5E_CANTDEC, (-1), "can't decrement ID ref count") /* Check if the ID still exists */ @@ -1002,31 +1036,66 @@ H5I_dec_app_ref(hid_t id) done: FUNC_LEAVE_NOAPI(ret_value) +} /* end H5I__dec_app_ref() */ + +/*------------------------------------------------------------------------- + * Function: H5I_dec_app_ref + * + * Purpose: 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: -1 + * + * Programmer: Quincey Koziol + * Sept 16, 2010 + * + *------------------------------------------------------------------------- + */ +int +H5I_dec_app_ref(hid_t id) +{ + int ret_value = 0; /* Return value */ + + FUNC_ENTER_NOAPI((-1)) + + /* Sanity check */ + HDassert(id >= 0); + + /* Synchronously decrement refcount on ID */ + if ((ret_value = H5I__dec_app_ref(id, H5_REQUEST_NULL)) < 0) + HGOTO_ERROR(H5E_ID, H5E_CANTDEC, (-1), "can't decrement ID ref count") + +done: + FUNC_LEAVE_NOAPI(ret_value) } /* end H5I_dec_app_ref() */ /*------------------------------------------------------------------------- - * Function: H5I_dec_app_ref_always_close + * Function: H5I__dec_app_ref_always_close * * Purpose: Wrapper for case of always closing the ID, even when the free * routine fails * + * Note: Allows for asynchronous 'close' operation on object, with + * request != H5_REQUEST_NULL. + * * Return: Success: New app. reference count * Failure: -1 * *------------------------------------------------------------------------- */ -int -H5I_dec_app_ref_always_close(hid_t id) +static int +H5I__dec_app_ref_always_close(hid_t id, void **request) { int ret_value = 0; /* Return value */ - FUNC_ENTER_NOAPI((-1)) + FUNC_ENTER_STATIC /* Sanity check */ HDassert(id >= 0); /* Call application decrement reference count routine */ - ret_value = H5I_dec_app_ref(id); + ret_value = H5I__dec_app_ref(id, request); /* Check for failure */ if (ret_value < 0) { @@ -1039,7 +1108,36 @@ H5I_dec_app_ref_always_close(hid_t id) H5I_remove(id); HGOTO_ERROR(H5E_ID, H5E_CANTDEC, (-1), "can't decrement ID ref count") - } + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5I__dec_app_ref_always_close() */ + +/*------------------------------------------------------------------------- + * Function: H5I_dec_app_ref_always_close + * + * Purpose: Wrapper for case of always closing the ID, even when the free + * routine fails. + * + * Return: Success: New app. reference count + * Failure: -1 + * + *------------------------------------------------------------------------- + */ +int +H5I_dec_app_ref_always_close(hid_t id) +{ + int ret_value = 0; /* Return value */ + + FUNC_ENTER_NOAPI((-1)) + + /* Sanity check */ + HDassert(id >= 0); + + /* Synchronously decrement refcount on ID */ + if ((ret_value = H5I__dec_app_ref_always_close(id, H5_REQUEST_NULL)) < 0) + HGOTO_ERROR(H5E_ID, H5E_CANTDEC, (-1), "can't decrement ID ref count") done: FUNC_LEAVE_NOAPI(ret_value) |