summaryrefslogtreecommitdiffstats
path: root/src/H5ESint.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@lbl.gov>2020-12-14 00:02:17 (GMT)
committerGitHub <noreply@github.com>2020-12-14 00:02:17 (GMT)
commita2524671caef27446e531a6eb9e20fcc1a2ff708 (patch)
treef500db8cc087b52b3b7739c0334b08b14def28f6 /src/H5ESint.c
parentf6dce729e8cf3d6d8675fbbfe1d66ac044ba02fb (diff)
downloadhdf5-a2524671caef27446e531a6eb9e20fcc1a2ff708.zip
hdf5-a2524671caef27446e531a6eb9e20fcc1a2ff708.tar.gz
hdf5-a2524671caef27446e531a6eb9e20fcc1a2ff708.tar.bz2
Bring async branch to develop (#166)
* Add H5Fwait, H5Dwait, and other changes for async vol connector * Revert temporary testing changes * Add H5Fwait to header file * Add H5VLreset_lib_state() routine. * Correct VOL wrap context when retrieving library state for file open & create. * Manage the API context's VOL connector state as part of the library state. * Set the 'VOL connector property valid' flag when restoring the library state. * Don't push new API context on stack when retrieving "current" one. * Check for NULL VOL wrap context before decrementing refcount on it, when freeing the API context state. * Manage recount of underlying connector for VOL wrap context. * Add H5TSmutex_acquire() and H5TSmutex_release() routines to acquire and release the global lock on the HDF5 library. * Update library with new functions related to library global lock * Add asynchronous token API * Add new lightweight FUNC_ENTER / LEAVE macros for helping to structure the threadsafety (H5TS*) routines. * Sync w/develop * Initial event set code framework. * Elaborate on the H5ES routines, starting to add API routines. Update the "close ID" callbacks to allow asynchronous request tokens to be passed in from an asynchronous close API call. Refactor current asynchronous API routines (H5Fopen/H5Fclose and H5Dread/H5Dread) to use event sets instead of directly working with request tokens from the application. Clean up a few other minor warnings & code style issues. * Implement H5EScreate, H5ESget_count, and H5ESclose. It should be possible to write a simple application that creates an event set and uses it with H5Fopen_async, H5Dread_async, H5Dwrite_async, and H5Fclose_async, then calls H5ESclose (which waits for all async events to complete). * Add source file for event set test. * Refactor sync & async API routines to call common routine. Move dataset API read / write routines to src/H5D.c, along with all the other API routines. Progress on "fake" async VOL connector, for testing. * Modify async implementation to wrap async requests in a H5VL_object_t struct so the VOL layer can find the connector when accessing the request at a later point. * Free the requests is H5ESclose. Remove comments implying that request wait, notify, and cancel callbacks should free the request. * Fix bug in error handling in H5Fclose. * Fix bugs in async file routines. Rename H5VL_create_object_generic to H5VL_create_object. * Add explicit async version of H5Fcreate. * Add more _async routines * Correct typo for return value from H5Awrite changes * Add H5EStest and H5ESwait routines * Updated with API tracing info * Fix NULL pointer dereference in H5ES__wait * Add H5is_library_terminating() routine, so that VOL connectors can detect when the library is shutting down. * Fix typo * Remove event from event set's linked list * Move block of code so that vol_obj is valid * Avoid setting properties in the DXPL when reseting the library state (and in the test code). * Refactor argument tracing to implement new capability for tracing arguments of non-API routines, with the H5ARG_TRACE macro. This macro is updated automatically with the bin/trace script that runs as part of the autogen.sh process. Major changes were in src/H5trace.c and bin/trace, with the other changes being cleanups to the argument lists, to improve their presentation in the tracing output. Also - added the "managed string" routines, which can dynamically allocate strings, appending printf-formatted output to the string efficiently. * Release memory for managed strings * Fix printf() formats. * More printf() format fixes. * Add H5Eappend_stack routine and regression tests * Clean up a few missed merge conflicts and update the error stacks. * Remove unnecessary fork() operations and ten second sleep(). * Restore commented out attribute out, to better enable tracking down the previous failure * Allow multiple H5ARG_TRACE macros within a routine to be updated * Switch to using "new" H5ES_insert (which takes the arguments for the caller routine) for all event set operations. Renames H5ES_insert_new to H5ES_insert and removes the previous H5ES_insert. * Merge "managed" string routines into "ref-counted" strings, and refactor code to use them. * Add missing file. * Add caller's name and arguments to event, for error reporting * Refactor event set setup for "API common" internal routines * Checkin async API routines for H5A* and H5G* modules as listed in ID-283. Fix couple h5dump expected output files due to the changes. * Add some of the error query routines needed for event sets. * Refactor to make async setup / teardown and "common" routines cleaner * (1) Add async APIs to H5L, H5F, and H5D modules (2) Fix errors in previous checkins of async APIs in H5A and H5G modules (3) h5dump expected output changes * Enhance event info, for better error handling * Change name of temporary vol_obj variable, to help reduce coding errors * Fix oversight with vol_obj pointer * Minor code cleanup * Add missing \'valid\' flag for VOL wrapper context, when restoring the library\'s state * Run source formatter * Change H5TSmutex lock and release to include a lock count * Update error reporting ideas * Minor updates to improve sanity checking for retrieving / restoring library state * Updated with feedback from h5py team members * Refactor internal event set list and event handling, add implementation for H5ESget_err_info * Change the VOL request subclass callbacks that switch from using "H5ES_status_t" to "H5VL_request_status_t", and also add a H5VL_request_status_t* parameter to the 'cancel' callback in the request subclass. Also more code quality cleanups to add iterator callbacks to internal event set routines. * Update API tracing for new H5VL_request_status_t typedef * Finish converting internal event set operations to use list iterator callbacks, instead of directly accessing the list structure * Add H5VL_REQUEST_GET_ERR_STACK operation to request subclass, for retrieving a copy of the error stack for a failed asynchronous operation * Remove 'canceled' event status from Java constants * Be safer about releasing resources when inserting a newly opened/created object or file into an event set * Remove H5EStest, add H5ES_WAIT_NONE for 0 timeout, and revise parameters to H5ESwait, to make it more "aggregate". * Remove H5ES_STATUS_CANCELED from Java wrappers also * (a) Add async APIs for H5O module as listed in jira issue ID-283. (b) Remove verification of name parameter in async related routines for H55A and H5L modules because it is checked in H5VL_setup* routine. (c) Modify h5dump expected output due to the async changes. * Corrections based on PR feedback. * Further changes to make based on PR feedback. * Fix missed merge marker, and reformatted line * Clean up some warnings * Correct level of indirection * Relocate prototype (and doxygen info) for H5Aclose * Change non-static function declarations to be static * Ensure that H5TSpublic.h header gets installed (#129) * Add 'wrapper' versions of async calls, to allow language wrappers and layers on top of HDF5 to pass in their application information. * Switch H5Aexists\*_async and H5Lexists\*_async to use flag to return status, instead of return value. Make the corresponding changes through most of the v1 and v2 B-tree code. Clean up warnings in H5public.h and cmpd_dtransform.c. * Add H5Iregister_future routine and tests. * Correct return value for H5Lexists_async * Add H5_DLL macro to public H5ES API routines * Update supported -> flags parameter for introspect_query callback * Remove my email address. Update passthrough VOL connector ID. * Fix comment for post_open_api_common * Remove unused non-blocking VOL connector * Minor cleanup in async branch in preparation for merge to develop * Update CMake and the Autotools to use the new pass-through VOL ID * Fix for SWMR daily test failures (#160) The H5I_register_using_existing_id() call did not initialize the future ID callbacks, causing the library to segfault when it tried to resolve those function pointers. * Added selective async APIs (#150) * Added selective async APIs Description: Added the following APIs: H5Ropen_attr_async H5Ropen_object_async H5Ropen_region_async H5Mcreate_async H5Mopen_async H5Mput_async H5Mget_async H5Mclose_async H5Tcommit_async H5Topen_async H5Tcopy_async H5Tclose_async - Updated an expected output file to include a new internal function in the error stack for the failure case. * Updated async APIs per reviews, including removing async version of H5Tcopy. * Removed statements that were added by mistake in the previous commit. * Fix compile issues in H5M and warnings elsewhere * Reformat code * Brings VOL_LIST changes from develop. (#163) Co-authored-by: Houjun Tang <htang4@lbl.gov> Co-authored-by: Neil Fortner <nfortne2@hdfgroup.org> Co-authored-by: vchoi <vchoi@jelly.ad.hdfgroup.org> Co-authored-by: vchoi-hdfgroup <55293060+vchoi-hdfgroup@users.noreply.github.com> Co-authored-by: jhendersonHDF <jhenderson@hdfgroup.org> Co-authored-by: Dana Robinson <derobins@hdfgroup.org> Co-authored-by: Dana Robinson <43805+derobins@users.noreply.github.com> Co-authored-by: bmribler <39579120+bmribler@users.noreply.github.com>
Diffstat (limited to 'src/H5ESint.c')
-rw-r--r--src/H5ESint.c666
1 files changed, 666 insertions, 0 deletions
diff --git a/src/H5ESint.c b/src/H5ESint.c
new file mode 100644
index 0000000..17d7806
--- /dev/null
+++ b/src/H5ESint.c
@@ -0,0 +1,666 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the COPYING file, which can be found at the root of the source code *
+ * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*-------------------------------------------------------------------------
+ *
+ * Created: H5ESint.c
+ * Apr 8 2020
+ * Quincey Koziol
+ *
+ * Purpose: Internal "event set" routines for managing asynchronous
+ * operations.
+ *
+ * Please see the asynchronous I/O RFC document
+ * for a full description of how they work, etc.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/****************/
+/* Module Setup */
+/****************/
+
+#include "H5ESmodule.h" /* This source code file is part of the H5ES module */
+
+/***********/
+/* Headers */
+/***********/
+#include "H5private.h" /* Generic Functions */
+#include "H5Eprivate.h" /* Error handling */
+#include "H5ESpkg.h" /* Event Sets */
+#include "H5FLprivate.h" /* Free Lists */
+#include "H5Iprivate.h" /* IDs */
+#include "H5MMprivate.h" /* Memory management */
+#include "H5RSprivate.h" /* Reference-counted strings */
+
+/****************/
+/* Local Macros */
+/****************/
+
+/******************/
+/* Local Typedefs */
+/******************/
+
+/* Callback context for wait operations */
+typedef struct H5ES_wait_ctx_t {
+ H5ES_t * es; /* Event set being operated on */
+ uint64_t timeout; /* Timeout for wait operation */
+ size_t * num_in_progress; /* Count of # of operations that have not completed */
+ hbool_t *op_failed; /* Flag to indicate an operation failed */
+} H5ES_wait_ctx_t;
+
+/* Callback context for get error info (gei) operations */
+typedef struct H5ES_gei_ctx_t {
+ H5ES_t * es; /* Event set being operated on */
+ size_t num_err_info; /* # of elements in err_info[] array */
+ size_t curr_err; /* Index of current error in array */
+ H5ES_err_info_t *curr_err_info; /* Pointer to current element in err_info[] array */
+} H5ES_gei_ctx_t;
+
+/********************/
+/* Package Typedefs */
+/********************/
+
+/********************/
+/* Local Prototypes */
+/********************/
+static herr_t H5ES__close_cb(void *es, void **request_token);
+static herr_t H5ES__handle_fail(H5ES_t *es, H5ES_event_t *ev);
+static int H5ES__wait_cb(H5ES_event_t *ev, void *_ctx);
+static int H5ES__get_err_info_cb(H5ES_event_t *ev, void *_ctx);
+static int H5ES__close_failed_cb(H5ES_event_t *ev, void *_ctx);
+
+/*********************/
+/* Package Variables */
+/*********************/
+
+/* Package initialization variable */
+hbool_t H5_PKG_INIT_VAR = FALSE;
+
+/*****************************/
+/* Library Private Variables */
+/*****************************/
+
+/*******************/
+/* Local Variables */
+/*******************/
+
+/* Event Set ID class */
+static const H5I_class_t H5I_EVENTSET_CLS[1] = {{
+ H5I_EVENTSET, /* ID class value */
+ 0, /* Class flags */
+ 0, /* # of reserved IDs for class */
+ (H5I_free_t)H5ES__close_cb /* Callback routine for closing objects of this class */
+}};
+
+/* Declare a static free list to manage H5ES_t structs */
+H5FL_DEFINE_STATIC(H5ES_t);
+
+/*-------------------------------------------------------------------------
+ * Function: H5ES__init_package
+ *
+ * Purpose: Initializes any interface-specific data or routines.
+ *
+ * Return: Non-negative on success / Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * Monday, April 6, 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5ES__init_package(void)
+{
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_PACKAGE
+
+ /* Initialize the ID group for the event set IDs */
+ if (H5I_register_type(H5I_EVENTSET_CLS) < 0)
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTINIT, FAIL, "unable to initialize interface")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5ES__init_package() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5ES_term_package
+ *
+ * Purpose: Terminate this interface.
+ *
+ * Return: Success: Positive if anything is done that might
+ * affect other interfaces; zero otherwise.
+ * Failure: Negative
+ *
+ * Programmer: Quincey Koziol
+ * Monday, April 6, 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+H5ES_term_package(void)
+{
+ int n = 0;
+
+ FUNC_ENTER_NOAPI_NOINIT_NOERR
+
+ if (H5_PKG_INIT_VAR) {
+ /* Destroy the event set ID group */
+ n += (H5I_dec_type_ref(H5I_EVENTSET) > 0);
+
+ /* Mark closed */
+ if (0 == n)
+ H5_PKG_INIT_VAR = FALSE;
+ } /* end if */
+
+ FUNC_LEAVE_NOAPI(n)
+} /* end H5ES_term_package() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5ES__close_cb
+ *
+ * Purpose: Called when the ref count reaches zero on an event set's ID
+ *
+ * Return: SUCCEED / FAIL
+ *
+ * Programmer: Quincey Koziol
+ * Monday, April 6, 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5ES__close_cb(void *_es, void H5_ATTR_UNUSED **rt)
+{
+ H5ES_t *es = (H5ES_t *)_es; /* The event set to close */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_STATIC
+
+ /* Sanity check */
+ HDassert(es);
+
+ /* Close the event set object */
+ if (H5ES__close(es) < 0)
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CLOSEERROR, FAIL, "unable to close event set");
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5ES__close_cb() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5ES__create
+ *
+ * Purpose: Private function to create an event set object
+ *
+ * Return: Success: Pointer to an event set struct
+ * Failure: NULL
+ *
+ * Programmer: Quincey Koziol
+ * Wednesday, April 8, 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+H5ES_t *
+H5ES__create(void)
+{
+ H5ES_t *es = NULL; /* Pointer to event set */
+ H5ES_t *ret_value = NULL; /* Return value */
+
+ FUNC_ENTER_PACKAGE
+
+ /* Allocate space for new event set */
+ if (NULL == (es = H5FL_CALLOC(H5ES_t)))
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTALLOC, NULL, "can't allocate event set object")
+
+ /* Set the return value */
+ ret_value = es;
+
+done:
+ if (!ret_value)
+ if (es && H5ES__close(es) < 0)
+ HDONE_ERROR(H5E_EVENTSET, H5E_CANTRELEASE, NULL, "unable to free event set")
+
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5ES__create() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5ES_insert
+ *
+ * Purpose: Insert a request token into an event set
+ *
+ * Return: SUCCEED / FAIL
+ *
+ * Programmer: Quincey Koziol
+ * Wednesday, April 8, 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5ES_insert(hid_t es_id, H5VL_t *connector, void *token, const char *caller, const char *caller_args, ...)
+{
+ H5ES_t * es = NULL; /* Event set for the operation */
+ H5ES_event_t *ev = NULL; /* Event for request */
+ H5RS_str_t * rs = NULL; /* Ref-counted string to compose formatted argument string in */
+ const char * app_file; /* Application source file name */
+ const char * app_func; /* Application source function name */
+ const char * s; /* Pointer to internal string from ref-counted string */
+ va_list ap; /* Varargs for caller */
+ hbool_t arg_started = FALSE; /* Whether the va_list has been started */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI(FAIL)
+
+ /* Sanity check */
+ HDassert(connector);
+ HDassert(token);
+ HDassert(caller);
+ HDassert(caller_args);
+
+ /* Get event set */
+ if (NULL == (es = (H5ES_t *)H5I_object_verify(es_id, H5I_EVENTSET)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an event set")
+
+ /* Check for errors in event set */
+ if (es->err_occurred)
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTINSERT, FAIL, "event set has failed operations")
+
+ /* Create new event */
+ if (NULL == (ev = H5ES__event_new(connector, token)))
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTCREATE, FAIL, "can't create event object")
+
+ /* Start working on the API routines arguments */
+ HDva_start(ap, caller_args);
+ arg_started = TRUE;
+
+ /* Copy the app source information */
+ (void)HDva_arg(ap, char *); /* Toss the 'app_file' parameter name */
+ app_file = HDva_arg(ap, char *);
+ if (NULL == (ev->app_file = H5MM_strdup(app_file)))
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTALLOC, FAIL, "can't copy app source file name")
+ (void)HDva_arg(ap, char *); /* Toss the 'app_func' parameter name */
+ app_func = HDva_arg(ap, char *);
+ if (NULL == (ev->app_func = H5MM_strdup(app_func)))
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTALLOC, FAIL, "can't copy app source function name")
+ (void)HDva_arg(ap, char *); /* Toss the 'app_line' parameter name */
+ ev->app_line = HDva_arg(ap, unsigned);
+
+ /* Set the event's operation counter */
+ ev->ev_count = es->op_counter++;
+
+ /* Set the event's timestamp */
+ ev->ev_time = H5_now_usec();
+
+ /* Copy the API routine's name */
+ if (NULL == (ev->api_name = H5MM_strdup(caller)))
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTALLOC, FAIL, "can't copy API routine name")
+
+ /* Create the string for the API routine's arguments */
+ if (NULL == (rs = H5RS_create(NULL)))
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTALLOC, FAIL, "can't allocate ref-counted string")
+
+ /* Copy the string for the API routine's arguments */
+ /* (skip the six characters from the app's file, function and line # arguments) */
+ HDassert(0 == HDstrncmp(caller_args, "*s*sIu", 6));
+ if (H5_trace_args(rs, caller_args + 6, ap) < 0)
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTSET, FAIL, "can't create formatted API arguments")
+ if (NULL == (s = H5RS_get_str(rs)))
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTGET, FAIL, "can't get pointer to formatted API arguments")
+ if (NULL == (ev->api_args = H5MM_strdup(s)))
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTALLOC, FAIL, "can't copy API routine arguments")
+
+ /* Append fully initialized event onto the event set's 'active' list */
+ H5ES__list_append(&es->active, ev);
+
+done:
+ /* Clean up */
+ if (arg_started)
+ HDva_end(ap);
+ if (rs)
+ H5RS_decr(rs);
+
+ /* Release resources on error */
+ if (ret_value < 0)
+ if (ev && H5ES__event_free(ev) < 0)
+ HDONE_ERROR(H5E_EVENTSET, H5E_CANTRELEASE, FAIL, "unable to release event")
+
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5ES_insert() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5ES__handle_fail
+ *
+ * Purpose: Handle a failed event
+ *
+ * Return: SUCCEED / FAIL
+ *
+ * Programmer: Quincey Koziol
+ * Thursday, October 15, 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5ES__handle_fail(H5ES_t *es, H5ES_event_t *ev)
+{
+ FUNC_ENTER_STATIC_NOERR
+
+ /* Sanity check */
+ HDassert(es);
+ HDassert(es->active.head);
+ HDassert(ev);
+
+ /* Set error flag for event set */
+ es->err_occurred = TRUE;
+
+ /* Remove event from normal list */
+ H5ES__list_remove(&es->active, ev);
+
+ /* Append event onto the event set's error list */
+ H5ES__list_append(&es->failed, ev);
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* end H5ES__handle_fail() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5ES__wait_cb
+ *
+ * Purpose: Common routine for testing / waiting on an operation
+ *
+ * Return: SUCCEED / FAIL
+ *
+ * Programmer: Quincey Koziol
+ * Sunday, November 7, 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+H5ES__wait_cb(H5ES_event_t *ev, void *_ctx)
+{
+ H5ES_wait_ctx_t * ctx = (H5ES_wait_ctx_t *)_ctx; /* Callback context */
+ H5VL_request_status_t ev_status = H5VL_REQUEST_STATUS_SUCCEED; /* Status from event's operation */
+ uint64_t start_time = 0, elapsed_time = 0; /* Start and elapsed times for waiting on an operation */
+ int ret_value = H5_ITER_CONT; /* Return value */
+
+ FUNC_ENTER_STATIC
+
+ /* Sanity check */
+ HDassert(ev);
+ HDassert(ctx);
+
+ /* Wait on the request */
+ if (ctx->timeout != H5ES_WAIT_NONE && ctx->timeout != H5ES_WAIT_FOREVER)
+ start_time = H5_now_usec();
+ if (H5VL_request_wait(ev->request, ctx->timeout, &ev_status) < 0)
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTWAIT, H5_ITER_ERROR, "unable to test operation")
+ if (ctx->timeout != H5ES_WAIT_NONE && ctx->timeout != H5ES_WAIT_FOREVER)
+ elapsed_time = H5_now_usec() - start_time;
+
+ /* Check for status values that indicate we should break out of the loop */
+ if (ev_status == H5VL_REQUEST_STATUS_FAIL) {
+ /* Handle failure */
+ if (H5ES__handle_fail(ctx->es, ev) < 0)
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTSET, H5_ITER_ERROR, "unable to handle failed event")
+
+ /* Record the error */
+ *ctx->op_failed = TRUE;
+
+ /* Exit from the iteration */
+ ret_value = H5_ITER_STOP;
+ } /* end if */
+ else if (ev_status == H5VL_REQUEST_STATUS_SUCCEED) {
+ if (H5ES__event_completed(ev, &ctx->es->active) < 0)
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTRELEASE, H5_ITER_ERROR, "unable to release completed event")
+ } /* end else-if */
+ else if (ev_status == H5VL_REQUEST_STATUS_CANCELED)
+ /* Should never get a status of 'cancel' back from test / wait operation */
+ HGOTO_ERROR(H5E_EVENTSET, H5E_BADVALUE, H5_ITER_ERROR, "received 'cancel' status for operation")
+ else {
+ /* Sanity check */
+ HDassert(ev_status == H5VL_REQUEST_STATUS_IN_PROGRESS);
+
+ /* Increment "in progress operation" counter */
+ (*ctx->num_in_progress)++;
+ } /* end if */
+
+ /* Check for updateable timeout */
+ if (ctx->timeout != H5ES_WAIT_NONE && ctx->timeout != H5ES_WAIT_FOREVER) {
+ /* Update timeout for next operation */
+ if ((elapsed_time * 1000) > ctx->timeout)
+ ctx->timeout = H5ES_WAIT_NONE;
+ else
+ ctx->timeout -= (elapsed_time * 1000); /* Convert us to ns */
+ } /* end if */
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5ES__wait_cb() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5ES__wait
+ *
+ * Purpose: Wait for operations in event set to complete
+ *
+ * Note: Timeout value is in ns, and is for H5ES__wait itself.
+ *
+ * Return: SUCCEED / FAIL
+ *
+ * Programmer: Quincey Koziol
+ * Monday, July 13, 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5ES__wait(H5ES_t *es, uint64_t timeout, size_t *num_in_progress, hbool_t *op_failed)
+{
+ H5ES_wait_ctx_t ctx; /* Iterator callback context info */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_PACKAGE
+
+ /* Sanity check */
+ HDassert(es);
+ HDassert(num_in_progress);
+ HDassert(op_failed);
+
+ /* Set user's parameters to known values */
+ *num_in_progress = 0;
+ *op_failed = FALSE;
+
+ /* Set up context for iterator callbacks */
+ ctx.es = es;
+ ctx.timeout = timeout;
+ ctx.num_in_progress = num_in_progress;
+ ctx.op_failed = op_failed;
+
+ /* Iterate over the events in the set, waiting for them to complete */
+ if (H5ES__list_iterate(&es->active, H5ES__wait_cb, &ctx) < 0)
+ HGOTO_ERROR(H5E_EVENTSET, H5E_BADITER, FAIL, "iteration failed")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5ES__wait() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5ES__get_err_info_cb
+ *
+ * Purpose: Retrieve information about a failed operation
+ *
+ * Return: SUCCEED / FAIL
+ *
+ * Programmer: Quincey Koziol
+ * Monday, November 11, 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+H5ES__get_err_info_cb(H5ES_event_t *ev, void *_ctx)
+{
+ H5ES_gei_ctx_t *ctx = (H5ES_gei_ctx_t *)_ctx; /* Callback context */
+ int ret_value = H5_ITER_CONT; /* Return value */
+
+ FUNC_ENTER_STATIC
+
+ /* Sanity check */
+ HDassert(ev);
+ HDassert(ctx);
+
+ /* Copy operation info for event */
+ if (NULL == (ctx->curr_err_info->api_name = H5MM_strdup(ev->api_name)))
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTALLOC, H5_ITER_ERROR, "can't copy HDF5 API name")
+ if (NULL == (ctx->curr_err_info->api_args = H5MM_strdup(ev->api_args)))
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTALLOC, H5_ITER_ERROR, "can't copy HDF5 API routine arguments")
+ if (NULL == (ctx->curr_err_info->app_file_name = H5MM_strdup(ev->app_file)))
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTALLOC, H5_ITER_ERROR, "can't copy app source file name")
+ if (NULL == (ctx->curr_err_info->app_func_name = H5MM_strdup(ev->app_func)))
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTALLOC, H5_ITER_ERROR, "can't copy app function name")
+ ctx->curr_err_info->app_line_num = ev->app_line;
+ ctx->curr_err_info->op_ins_count = ev->ev_count;
+ ctx->curr_err_info->op_ins_ts = ev->ev_time;
+
+ /* Get error stack for event */
+ if (H5VL_request_specific(ev->request, H5VL_REQUEST_GET_ERR_STACK, &ctx->curr_err_info->err_stack_id) < 0)
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTGET, H5_ITER_ERROR, "unable to retrieve error stack for operation")
+
+ /* Remove event from event set's failed list */
+ H5ES__list_remove(&ctx->es->failed, ev);
+
+ /* Free event node */
+ if (H5ES__event_free(ev) < 0)
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTRELEASE, H5_ITER_ERROR, "unable to release failed event")
+
+ /* Advance to next element of err_info[] array */
+ ctx->curr_err++;
+ ctx->curr_err_info++;
+
+ /* Stop iteration if err_info[] array is full */
+ if (ctx->curr_err == ctx->num_err_info)
+ ret_value = H5_ITER_STOP;
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5ES__get_err_info_cb() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5ES__get_err_info
+ *
+ * Purpose: Retrieve information about failed operations
+ *
+ * Return: SUCCEED / FAIL
+ *
+ * Programmer: Quincey Koziol
+ * Friday, November 6, 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5ES__get_err_info(H5ES_t *es, size_t num_err_info, H5ES_err_info_t err_info[], size_t *num_cleared)
+{
+ H5ES_gei_ctx_t ctx; /* Iterator callback context info */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_PACKAGE
+
+ /* Sanity check */
+ HDassert(es);
+ HDassert(num_err_info);
+ HDassert(err_info);
+ HDassert(num_cleared);
+
+ /* Set up context for iterator callbacks */
+ ctx.es = es;
+ ctx.num_err_info = num_err_info;
+ ctx.curr_err = 0;
+ ctx.curr_err_info = &err_info[0];
+
+ /* Iterate over the failed events in the set, copying their error info */
+ if (H5ES__list_iterate(&es->failed, H5ES__get_err_info_cb, &ctx) < 0)
+ HGOTO_ERROR(H5E_EVENTSET, H5E_BADITER, FAIL, "iteration failed")
+
+ /* Set # of failed events cleared from event set's failed list */
+ *num_cleared = ctx.curr_err;
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5ES__get_err_info() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5ES__close_failed_cb
+ *
+ * Purpose: Release a failed event
+ *
+ * Return: SUCCEED / FAIL
+ *
+ * Programmer: Quincey Koziol
+ * Monday, November 11, 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+H5ES__close_failed_cb(H5ES_event_t *ev, void *_ctx)
+{
+ H5ES_t *es = (H5ES_t *)_ctx; /* Callback context */
+ int ret_value = H5_ITER_CONT; /* Return value */
+
+ FUNC_ENTER_PACKAGE
+
+ /* Sanity check */
+ HDassert(ev);
+ HDassert(es);
+
+ /* Remove event from event set's failed list */
+ H5ES__list_remove(&es->failed, ev);
+
+ /* Free event node */
+ if (H5ES__event_free(ev) < 0)
+ HGOTO_ERROR(H5E_EVENTSET, H5E_CANTRELEASE, H5_ITER_ERROR, "unable to release failed event")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5ES__close_failed_cb() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5ES__close
+ *
+ * Purpose: Destroy an event set object
+ *
+ * Return: SUCCEED / FAIL
+ *
+ * Programmer: Quincey Koziol
+ * Monday, April 6, 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5ES__close(H5ES_t *es)
+{
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_PACKAGE
+
+ /* Sanity check */
+ HDassert(es);
+
+ /* Fail if active operations still present */
+ if (H5ES__list_count(&es->active) > 0)
+ HGOTO_ERROR(
+ H5E_EVENTSET, H5E_CANTCLOSEOBJ, FAIL,
+ "can't close event set while unfinished operations are present (i.e. wait on event set first)")
+
+ /* Iterate over the failed events in the set, releasing them */
+ if (H5ES__list_iterate(&es->failed, H5ES__close_failed_cb, (void *)es) < 0)
+ HGOTO_ERROR(H5E_EVENTSET, H5E_BADITER, FAIL, "iteration failed")
+
+ /* Release the event set */
+ es = H5FL_FREE(H5ES_t, es);
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5ES__close() */