Skip to content

Commit

Permalink
Refactor API context stack
Browse files Browse the repository at this point in the history
Reduce number of alloc/free calls and simplify code

Signed-off-by: Quincey Koziol <[email protected]>
  • Loading branch information
qkoziol committed Oct 9, 2024
1 parent 302ba0a commit 950731e
Show file tree
Hide file tree
Showing 56 changed files with 784 additions and 578 deletions.
5 changes: 3 additions & 2 deletions src/H5.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,10 @@ H5_term_library(void)
size_t nleft = sizeof(loop);
int nprinted;
H5E_auto2_t func;
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */

/* Acquire the API lock */
H5CANCEL_DECL
FUNC_ENTER_API_VARS
H5_API_LOCK

/* Don't do anything if the library is already closed */
Expand All @@ -310,7 +311,7 @@ H5_term_library(void)
H5_TERM_GLOBAL = true;

/* Push the API context without checking for errors */
H5CX_push_special();
H5CX_push(&api_ctx);

/* Check if we should display error output */
(void)H5Eget_auto2(H5E_DEFAULT, &func, NULL);
Expand Down
3 changes: 2 additions & 1 deletion src/H5Atest.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ herr_t
H5A__get_shared_rc_test(hid_t attr_id, hsize_t *ref_count)
{
H5A_t *attr; /* Attribute object for ID */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
herr_t ret_value = SUCCEED; /* Return value */

Expand All @@ -116,7 +117,7 @@ H5A__get_shared_rc_test(hid_t attr_id, hsize_t *ref_count)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute");

/* Push API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down
418 changes: 47 additions & 371 deletions src/H5CX.c

Large diffs are not rendered by default.

238 changes: 234 additions & 4 deletions src/H5CXprivate.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/H5FDprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ H5_DLL htri_t H5FD_is_driver_registered_by_name(const char *driver_name,
H5_DLL htri_t H5FD_is_driver_registered_by_value(H5FD_class_value_t driver_value, hid_t *registered_id);
H5_DLL hid_t H5FD_get_driver_id_by_name(const char *name, bool is_api);
H5_DLL hid_t H5FD_get_driver_id_by_value(H5FD_class_value_t value, bool is_api);
H5_DLL herr_t H5FD_open(bool try, H5FD_t **file, const char *name, unsigned flags, hid_t fapl_id,
H5_DLL herr_t H5FD_open(bool attempt, H5FD_t **file, const char *name, unsigned flags, hid_t fapl_id,
haddr_t maxaddr);
H5_DLL herr_t H5FD_close(H5FD_t *file);
H5_DLL int H5FD_cmp(const H5FD_t *f1, const H5FD_t *f2);
Expand Down
4 changes: 2 additions & 2 deletions src/H5Fprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ typedef enum H5F_prefix_open_t {

/* Private functions */
H5_DLL herr_t H5F_init(void);
H5_DLL herr_t H5F_open(bool try, H5F_t **file, const char *name, unsigned flags, hid_t fcpl_id,
H5_DLL herr_t H5F_open(bool attempt, H5F_t **file, const char *name, unsigned flags, hid_t fcpl_id,
hid_t fapl_id);
H5_DLL herr_t H5F_try_close(H5F_t *f, bool *was_closed /*out*/);
H5_DLL hid_t H5F_get_file_id(H5VL_object_t *vol_obj, H5I_type_t obj_type, bool app_ref);
Expand Down Expand Up @@ -657,7 +657,7 @@ H5_DLL herr_t H5F_shared_get_mpi_file_sync_required(const H5F_shared_t *f_sh,
H5_DLL herr_t H5F_efc_close(H5F_t *parent, H5F_t *file);

/* File prefix routines */
H5_DLL herr_t H5F_prefix_open_file(bool try, H5F_t **file, H5F_t *primary_file, H5F_prefix_open_t prefix_type,
H5_DLL herr_t H5F_prefix_open_file(bool attempt, H5F_t **file, H5F_t *primary_file, H5F_prefix_open_t prefix_type,
const char *prop_prefix, const char *file_name, unsigned file_intent,
hid_t fapl_id);

Expand Down
6 changes: 4 additions & 2 deletions src/H5Ftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ herr_t
H5F__get_sohm_mesg_count_test(hid_t file_id, unsigned type_id, size_t *mesg_count)
{
H5F_t *file; /* File info */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
herr_t ret_value = SUCCEED; /* Return value */

Expand All @@ -93,7 +94,7 @@ H5F__get_sohm_mesg_count_test(hid_t file_id, unsigned type_id, size_t *mesg_coun
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file");

/* Push API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down Expand Up @@ -124,6 +125,7 @@ herr_t
H5F__check_cached_stab_test(hid_t file_id)
{
H5F_t *file; /* File info */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
herr_t ret_value = SUCCEED; /* Return value */

Expand All @@ -134,7 +136,7 @@ H5F__check_cached_stab_test(hid_t file_id)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file");

/* Push API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down
21 changes: 14 additions & 7 deletions src/H5Gtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ H5G__is_empty_test(hid_t gid)
H5G_t *grp = NULL; /* Pointer to group */
htri_t msg_exists = false; /* Indicate that a header message is present */
htri_t linfo_exists = false; /* Indicate that the 'link info' message is present */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
htri_t ret_value = true; /* Return value */

Expand All @@ -96,7 +97,7 @@ H5G__is_empty_test(hid_t gid)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group");

/* Set API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down Expand Up @@ -205,6 +206,7 @@ H5G__has_links_test(hid_t gid, unsigned *nmsgs)
{
H5G_t *grp = NULL; /* Pointer to group */
htri_t msg_exists = 0; /* Indicate that a header message is present */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
htri_t ret_value = true; /* Return value */

Expand All @@ -215,7 +217,7 @@ H5G__has_links_test(hid_t gid, unsigned *nmsgs)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group");

/* Set API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down Expand Up @@ -271,6 +273,7 @@ H5G__has_stab_test(hid_t gid)
{
H5G_t *grp = NULL; /* Pointer to group */
htri_t msg_exists = 0; /* Indicate that a header message is present */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
htri_t ret_value = true; /* Return value */

Expand All @@ -281,7 +284,7 @@ H5G__has_stab_test(hid_t gid)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group");

/* Set API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down Expand Up @@ -329,6 +332,7 @@ H5G__is_new_dense_test(hid_t gid)
{
H5G_t *grp = NULL; /* Pointer to group */
htri_t msg_exists = 0; /* Indicate that a header message is present */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
htri_t ret_value = true; /* Return value */

Expand All @@ -339,7 +343,7 @@ H5G__is_new_dense_test(hid_t gid)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group");

/* Set API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down Expand Up @@ -407,6 +411,7 @@ H5G__new_dense_info_test(hid_t gid, hsize_t *name_count, hsize_t *corder_count)
H5B2_t *bt2_corder = NULL; /* v2 B-tree handle for creation order index */
H5O_linfo_t linfo; /* Link info message */
H5G_t *grp = NULL; /* Pointer to group */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
herr_t ret_value = SUCCEED; /* Return value */

Expand All @@ -417,7 +422,7 @@ H5G__new_dense_info_test(hid_t gid, hsize_t *name_count, hsize_t *corder_count)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group");

/* Set API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down Expand Up @@ -496,6 +501,7 @@ H5G__lheap_size_test(hid_t gid, size_t *lheap_size)
{
H5G_t *grp = NULL; /* Pointer to group */
H5O_stab_t stab; /* Symbol table message */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
herr_t ret_value = SUCCEED; /* Return value */

Expand All @@ -506,7 +512,7 @@ H5G__lheap_size_test(hid_t gid, size_t *lheap_size)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group");

/* Set API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down Expand Up @@ -552,6 +558,7 @@ H5G__user_path_test(hid_t obj_id, char *user_path, size_t *user_path_len, unsign
{
void *obj_ptr; /* Pointer to object for ID */
const H5G_name_t *obj_path; /* Pointer to group hier. path for obj */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
herr_t ret_value = SUCCEED; /* Return value */

Expand All @@ -566,7 +573,7 @@ H5G__user_path_test(hid_t obj_id, char *user_path, size_t *user_path_len, unsign
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "can't get object for ID");

/* Set API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down
3 changes: 2 additions & 1 deletion src/H5Itest.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ H5I__get_name_test(hid_t id, char *name /*out*/, size_t size, bool *cached)
{
H5VL_object_t *vol_obj; /* Object of id */
H5G_loc_t loc; /* Object location */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
bool vol_wrapper_set = false; /* Whether the VOL object wrapping context was set up */
size_t name_len = 0; /* Length of name */
Expand All @@ -73,7 +74,7 @@ H5I__get_name_test(hid_t id, char *name /*out*/, size_t size, bool *cached)
FUNC_ENTER_PACKAGE

/* Set API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTSET, (-1), "can't set API context");
api_ctx_pushed = true;

Expand Down
18 changes: 12 additions & 6 deletions src/H5Otest.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ H5O__is_attr_dense_test(hid_t oid)
H5O_t *oh = NULL; /* Object header */
H5O_ainfo_t ainfo; /* Attribute information for object */
H5O_loc_t *loc; /* Pointer to object's location */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
htri_t ret_value = FAIL; /* Return value */

Expand All @@ -95,7 +96,7 @@ H5O__is_attr_dense_test(hid_t oid)
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found");

/* Set API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down Expand Up @@ -157,6 +158,7 @@ H5O__is_attr_empty_test(hid_t oid)
htri_t ainfo_exists = false; /* Whether the attribute info exists in the file */
H5O_loc_t *loc; /* Pointer to object's location */
hsize_t nattrs; /* Number of attributes */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
htri_t ret_value = FAIL; /* Return value */

Expand All @@ -167,7 +169,7 @@ H5O__is_attr_empty_test(hid_t oid)
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found");

/* Set API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down Expand Up @@ -259,6 +261,7 @@ H5O__num_attrs_test(hid_t oid, hsize_t *nattrs)
H5O_ainfo_t ainfo; /* Attribute information for object */
H5O_loc_t *loc; /* Pointer to object's location */
hsize_t obj_nattrs; /* Number of attributes */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
herr_t ret_value = SUCCEED; /* Return value */

Expand All @@ -269,7 +272,7 @@ H5O__num_attrs_test(hid_t oid, hsize_t *nattrs)
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found");

/* Set API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down Expand Up @@ -358,6 +361,7 @@ H5O__attr_dense_info_test(hid_t oid, hsize_t *name_count, hsize_t *corder_count)
H5B2_t *bt2_corder = NULL; /* v2 B-tree handle for creation order index */
H5O_ainfo_t ainfo; /* Attribute information for object */
H5O_loc_t *loc; /* Pointer to object's location */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
herr_t ret_value = SUCCEED; /* Return value */

Expand All @@ -368,7 +372,7 @@ H5O__attr_dense_info_test(hid_t oid, hsize_t *name_count, hsize_t *corder_count)
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found");

/* Set API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down Expand Up @@ -628,6 +632,7 @@ H5O__msg_get_chunkno_test(hid_t oid, unsigned msg_type, unsigned *chunk_num)
H5O_loc_t *loc; /* Pointer to object's location */
H5O_mesg_t *idx_msg; /* Pointer to message */
unsigned idx; /* Index of message */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
herr_t ret_value = SUCCEED; /* Return value */

Expand All @@ -638,7 +643,7 @@ H5O__msg_get_chunkno_test(hid_t oid, unsigned msg_type, unsigned *chunk_num)
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found");

/* Set API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down Expand Up @@ -695,6 +700,7 @@ H5O__msg_move_to_new_chunk_test(hid_t oid, unsigned msg_type)
H5O_loc_t *loc; /* Pointer to object's location */
H5O_mesg_t *curr_msg; /* Pointer to current message */
unsigned idx; /* Index of message */
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
bool api_ctx_pushed = false; /* Whether API context pushed */
herr_t ret_value = SUCCEED; /* Return value */

Expand All @@ -705,7 +711,7 @@ H5O__msg_move_to_new_chunk_test(hid_t oid, unsigned msg_type)
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found");

/* Set API context */
if (H5CX_push() < 0)
if (H5CX_push(&api_ctx) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTSET, FAIL, "can't set API context");
api_ctx_pushed = true;

Expand Down
6 changes: 3 additions & 3 deletions src/H5TSmutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

#ifdef H5_HAVE_C11_THREADS

#define H5TS_mutex_lock(mutex) ((H5_UNLIKELY(mtx_lock(mutex) != thrd_success)) ? FAIL : SUCCEED)
#define H5TS_mutex_lock(mutex) (H5_UNLIKELY(mtx_lock(mutex) != thrd_success) ? FAIL : SUCCEED)
#define H5TS_mutex_unlock(mutex) (H5_UNLIKELY(mtx_unlock(mutex) != thrd_success) ? FAIL : SUCCEED)

#else
Expand Down Expand Up @@ -94,8 +94,8 @@ H5TS_mutex_unlock(H5TS_mutex_t *mutex)
} /* end H5TS_mutex_unlock() */
#else

#define H5TS_mutex_lock(mutex) (H5_UNLIKELY(pthread_mutex_lock(mutex)) ? FAIL : SUCCEED)
#define H5TS_mutex_unlock(mutex) (H5_UNLIKELY(pthread_mutex_unlock(mutex)) ? FAIL : SUCCEED)
#define H5TS_mutex_lock(mutex) (H5_UNLIKELY(0 != pthread_mutex_lock(mutex)) ? FAIL : SUCCEED)
#define H5TS_mutex_unlock(mutex) (H5_UNLIKELY(0 != pthread_mutex_unlock(mutex)) ? FAIL : SUCCEED)

#endif
#endif
Loading

0 comments on commit 950731e

Please sign in to comment.