diff options
author | Dana Robinson <43805+derobins@users.noreply.github.com> | 2021-03-01 22:06:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-01 22:06:03 (GMT) |
commit | db95737047fbbf967d928bf9a693d470884f4890 (patch) | |
tree | df63cc53b0f0aae8ffa8ad58fe31f21aff71c79b /test | |
parent | 511b940da6fa60e163f6f94e423f6cbd2879468d (diff) | |
parent | d7b277a22aa72f3badcc331e3007df8892e83a80 (diff) | |
download | hdf5-db95737047fbbf967d928bf9a693d470884f4890.zip hdf5-db95737047fbbf967d928bf9a693d470884f4890.tar.gz hdf5-db95737047fbbf967d928bf9a693d470884f4890.tar.bz2 |
Merge pull request #388 from derobins/vfd_swmr/H5FD_public_fix
Moves the BSD queue to a wrapper to keep it out of the public API
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 8 | ||||
-rw-r--r-- | test/vfd_swmr_common.c | 87 | ||||
-rw-r--r-- | test/vfd_swmr_common.h | 6 |
3 files changed, 97 insertions, 4 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 023c07e..ad6b258 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -46,6 +46,11 @@ if (NOT ONLY_SHARED_LIBS) endif () H5_SET_LIB_OPTIONS (${HDF5_TEST_LIB_TARGET} ${HDF5_TEST_LIB_NAME} STATIC 0) set_target_properties (${HDF5_TEST_LIB_TARGET} PROPERTIES FOLDER libraries/test) + + # Always link to pthreads for VFD SWMR tests + if (NOT WIN32) + target_link_libraries (${HDF5_TEST_LIB_TARGET} PRIVATE Threads::Threads) + endif () endif () if (BUILD_SHARED_LIBS) @@ -66,6 +71,9 @@ if (BUILD_SHARED_LIBS) endif () H5_SET_LIB_OPTIONS (${HDF5_TEST_LIBSH_TARGET} ${HDF5_TEST_LIB_NAME} SHARED "LIB") set_target_properties (${HDF5_TEST_LIBSH_TARGET} PROPERTIES FOLDER libraries/test) + + # Always link to pthreads for VFD SWMR tests + target_link_libraries (${HDF5_TEST_LIBSH_TARGET} PRIVATE Threads::Threads) endif () ################################################################################# diff --git a/test/vfd_swmr_common.c b/test/vfd_swmr_common.c index 043b7ed..3f03ce7 100644 --- a/test/vfd_swmr_common.c +++ b/test/vfd_swmr_common.c @@ -21,6 +21,11 @@ #include <err.h> /* for err(3) */ +/* Only need the pthread solution if sigtimedwai(2) isn't available */ +#ifndef H5_HAVE_SIGTIMEDWAIT +#include <pthread.h> +#endif + #include "h5test.h" #include "vfd_swmr_common.h" #include "swmr_common.h" @@ -178,6 +183,55 @@ strsignal(int signum) } #endif +#ifndef H5_HAVE_SIGTIMEDWAIT + +typedef struct timer_params_t { + struct timespec *tick; + hid_t fid; +} timer_params_t; + +pthread_mutex_t timer_mutex; +hbool_t timer_stop = FALSE; + +static void * +timer_function(void *arg) +{ + timer_params_t *params = (timer_params_t *)arg; + sigset_t sleepset; + hbool_t done = FALSE; + + /* Ignore any signals */ + sigfillset(&sleepset); + pthread_sigmask(SIG_SETMASK, &sleepset, NULL); + + for (;;) { + estack_state_t es; + + nanosleep(params->tick, NULL); + + /* Check the mutex */ + pthread_mutex_lock(&timer_mutex); + done = timer_stop; + pthread_mutex_unlock(&timer_mutex); + if (done) + break; + + /* Avoid deadlock with peer: periodically enter the API so that + * tick processing occurs and data is flushed so that the peer + * can see it. + * + * The call we make will fail, but that's ok, + * so squelch errors. + */ + es = disable_estack(); + (void)H5Aexists_by_name(params->fid, "nonexistent", "nonexistent", H5P_DEFAULT); + restore_estack(es); + } + + return NULL; +} +#endif /* H5_HAVE_SIGTIMEDWAIT */ + /* Wait for any signal to occur and then return. Wake periodically * during the wait to perform API calls: in this way, the * VFD SWMR tick number advances and recent changes do not languish @@ -186,8 +240,8 @@ strsignal(int signum) void await_signal(hid_t fid) { - sigset_t sleepset; struct timespec tick = {.tv_sec = 0, .tv_nsec = 1000000000 / 100}; + sigset_t sleepset; if (sigfillset(&sleepset) == -1) { err(EXIT_FAILURE, "%s.%d: could not initialize signal mask", @@ -202,7 +256,37 @@ await_signal(hid_t fid) dbgf(1, "waiting for signal\n"); +#ifndef H5_HAVE_SIGTIMEDWAIT + { + /* Use an alternative scheme for platforms like MacOS that do not have + * sigtimedwait(2) + */ + timer_params_t params; + int rc; + pthread_t timer; + + params.tick = &tick; + params.fid = fid; + + pthread_mutex_init(&timer_mutex, NULL); + + pthread_create(&timer, NULL, timer_function, ¶ms); + + rc = sigwait(&sleepset, NULL); + + if (rc != -1) { + fprintf(stderr, "Received signal, wrapping things up.\n"); + pthread_mutex_lock(&timer_mutex); + timer_stop = TRUE; + pthread_mutex_unlock(&timer_mutex); + pthread_join(timer, NULL); + } + else + err(EXIT_FAILURE, "%s: sigtimedwait", __func__); + } +#else for (;;) { + /* Linux and other systems */ const int rc = sigtimedwait(&sleepset, NULL, &tick); if (rc != -1) { @@ -226,6 +310,7 @@ await_signal(hid_t fid) } else if (rc == -1) err(EXIT_FAILURE, "%s: sigtimedwait", __func__); } +#endif /* H5_HAVE_SIGTIMEDWAIT */ } /* Revised support routines that can be used for all VFD SWMR integration tests diff --git a/test/vfd_swmr_common.h b/test/vfd_swmr_common.h index a4bf50e..f64ee87 100644 --- a/test/vfd_swmr_common.h +++ b/test/vfd_swmr_common.h @@ -11,8 +11,8 @@ * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _VFD_SWMR_COMMON_H -#define _VFD_SWMR_COMMON_H +#ifndef VFD_SWMR_COMMON_H +#define VFD_SWMR_COMMON_H /***********/ /* Headers */ @@ -94,4 +94,4 @@ H5TEST_DLL int fetch_env_ulong(const char *, unsigned long, unsigned long *); extern int verbosity; -#endif /* _SWMR_COMMON_H */ +#endif /* SWMR_COMMON_H */ |