diff options
author | Dana Robinson <derobins@hdfgroup.org> | 2021-03-02 22:30:01 (GMT) |
---|---|---|
committer | Dana Robinson <derobins@hdfgroup.org> | 2021-03-02 22:30:01 (GMT) |
commit | ae24b82f778579795395510aee52293f41b95aad (patch) | |
tree | a27af16a2db96eeff18401a163aa8c45f4eeb879 /test/vfd_swmr_common.c | |
parent | 69b2061d68aa85c8925c15a334fc5c3fb12e377f (diff) | |
parent | db95737047fbbf967d928bf9a693d470884f4890 (diff) | |
download | hdf5-ae24b82f778579795395510aee52293f41b95aad.zip hdf5-ae24b82f778579795395510aee52293f41b95aad.tar.gz hdf5-ae24b82f778579795395510aee52293f41b95aad.tar.bz2 |
Brings MacOS fixes from main feature branch
Diffstat (limited to 'test/vfd_swmr_common.c')
-rw-r--r-- | test/vfd_swmr_common.c | 87 |
1 files changed, 86 insertions, 1 deletions
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 |