Skip to content

Commit

Permalink
Support virtual locks with CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Dec 24, 2024
1 parent 9f515ab commit 2b9126d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ endif ()
#-----------------------------------------------------------------------------
# Option to enable multi-thread capable library
#-----------------------------------------------------------------------------
set (H5_HAVE_VIRTUAL_LOCK 0)
option (HDF5_ENABLE_MULTITHREAD "Enable multi-thread library" OFF)
if (HDF5_ENABLE_MULTITHREAD)
if (HDF5_BUILD_FORTRAN)
Expand Down Expand Up @@ -966,6 +967,10 @@ if (HDF5_ENABLE_MULTITHREAD)

set (H5_HAVE_MULTITHREAD 1)
set (H5_MT_TEST_VOL_DIR "\"${HDF5_BINARY_DIR}/bin/\"")

if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
set (H5_HAVE_VIRTUAL_LOCK 1)
endif()
endif ()

#-----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions config/cmake/H5pubconf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@
/* Define if we have multi-thread support */
#cmakedefine H5_HAVE_MULTITHREAD @H5_HAVE_MULTITHREAD@

/* Define to enable the virtual ID locks */
#cmakedefine01 H5_HAVE_VIRTUAL_LOCK

/* Define to 1 if you have the <netdb.h> header file. */
#cmakedefine H5_HAVE_NETDB_H @H5_HAVE_NETDB_H@

Expand Down
11 changes: 9 additions & 2 deletions src/H5I.c
Original file line number Diff line number Diff line change
Expand Up @@ -2004,7 +2004,7 @@ bool H5I_is_default_id(hid_t id) {
/* Is this a predefined library type? */
if (H5I_TYPE(id) == H5I_DATATYPE) {
dtype = (H5T_t *)H5I_object_verify(id, H5I_DATATYPE);

assert(dtype);

if (H5T_is_immutable(dtype))
Expand Down Expand Up @@ -2054,6 +2054,10 @@ herr_t H5I_vlock_enter(hid_t id) {
if (H5I_is_default_id(id))
HGOTO_DONE(SUCCEED);

/* Try to get ID info - if it was already released, do nothing */
if ((id_info_ptr = H5I__find_id(id)) == NULL)
HGOTO_DONE(SUCCEED);

/* Ensure that we have exlusive write access to the ID */
do {
info_k = atomic_load(&(id_info_ptr->k));
Expand Down Expand Up @@ -2118,6 +2122,10 @@ herr_t H5I_vlock_exit(hid_t id) {
memset(&info_k, 0, sizeof(info_k));
memset(&mod_info_k, 0, sizeof(mod_info_k));

/* No-op for default ids */
if (H5I_is_default_id(id))
HGOTO_DONE(SUCCEED);

/* Get ID info */
if ((id_info_ptr = H5I__find_id(id)) == NULL)
/* Assume ID was released during the course of the API routine */
Expand All @@ -2129,7 +2137,6 @@ herr_t H5I_vlock_exit(hid_t id) {

/* Ensure that we have exlusive write access to the ID */
do {

info_k = atomic_load(&(id_info_ptr->k));

if (info_k.do_not_disturb) {
Expand Down
4 changes: 4 additions & 0 deletions src/H5Iint.c
Original file line number Diff line number Diff line change
Expand Up @@ -2908,6 +2908,7 @@ H5I__mark_node(void *_info, void H5_ATTR_UNUSED *key, void *_udata)
assert(info_k.do_not_disturb == mod_info_k.do_not_disturb);
assert(info_k.is_future == mod_info_k.is_future);
assert(info_k.have_global_mutex == mod_info_k.have_global_mutex);

#if H5_HAVE_VIRTUAL_LOCK
assert(info_k.lock_count == mod_info_k.lock_count);
assert(info_k.app_unlocks == mod_info_k.app_unlocks);
Expand Down Expand Up @@ -4069,6 +4070,7 @@ H5I_subst(hid_t id, const void *new_object)
mod_info_k.is_future = info_k.is_future;

mod_info_k.object = new_object;

#if H5_HAVE_VIRTUAL_LOCK
mod_info_k.lock_count = info_k.lock_count;
mod_info_k.app_unlocks = info_k.app_unlocks;
Expand Down Expand Up @@ -5460,6 +5462,7 @@ H5I__dec_ref(hid_t id, void **request, hbool_t app)
assert(info_k.do_not_disturb == mod_info_k.do_not_disturb);
assert(info_k.is_future == mod_info_k.is_future);
assert(info_k.have_global_mutex == mod_info_k.have_global_mutex);

#if H5_HAVE_VIRTUAL_LOCK
assert(info_k.lock_count == mod_info_k.lock_count);
assert(info_k.app_unlocks == mod_info_k.app_unlocks);
Expand Down Expand Up @@ -7170,6 +7173,7 @@ H5I__iterate_cb(void *_item, void H5_ATTR_UNUSED *_key, void *_udata)
assert(info_k.do_not_disturb == mod_info_k.do_not_disturb);
assert(info_k.is_future == mod_info_k.is_future);
assert(info_k.have_global_mutex == mod_info_k.have_global_mutex);

#if H5_HAVE_VIRTUAL_LOCK
assert(info_k.lock_count == mod_info_k.lock_count);
assert(info_k.app_unlocks == mod_info_k.app_unlocks);
Expand Down
2 changes: 0 additions & 2 deletions src/H5private.h
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,6 @@ extern hbool_t H5_libterm_g; /* Is the library being shutdown? */
}\
}\
assert(virtual_lock_success);\
/* HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to lock object");*/\
}

#define FUNC_LEAVE_VIRTUAL_LOCK(...) \
Expand All @@ -1543,7 +1542,6 @@ extern hbool_t H5_libterm_g; /* Is the library being shutdown? */
}\
}\
assert(virtual_lock_success_exit);\
/*HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to unlock object"); */\
}

#else /* H5_HAVE_VIRTUAL_LOCK */
Expand Down

0 comments on commit 2b9126d

Please sign in to comment.