From: Bart Van Assche Date: Sun, 29 Jan 2023 22:42:17 +0000 (-0800) Subject: drd/tests/pth_mutex_signal: Port to Darwin X-Git-Tag: VALGRIND_3_21_0~189 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4978c9f65742ced9cce4732bf4da40bc7324a8e4;p=thirdparty%2Fvalgrind.git drd/tests/pth_mutex_signal: Port to Darwin This patch includes a revert of commit 2e873534bb49 ("macOS: drd pth_mutex_signal test doesn't build"). --- diff --git a/drd/tests/Makefile.am b/drd/tests/Makefile.am index 157bedcf48..e3366a18a0 100755 --- a/drd/tests/Makefile.am +++ b/drd/tests/Makefile.am @@ -418,6 +418,7 @@ check_PROGRAMS = \ pth_detached3 \ pth_inconsistent_cond_wait \ pth_mutex_reinit \ + pth_mutex_signal \ pth_process_shared_mutex \ recursive_mutex \ rwlock_race \ @@ -502,10 +503,6 @@ if HAVE_PTHREAD_CREATE_GLIBC_2_0 check_PROGRAMS += pth_create_glibc_2_0 endif -if !VGCONF_OS_IS_DARWIN -check_PROGRAMS += pth_mutex_signal -endif - if HAVE_PTHREAD_SPINLOCK check_PROGRAMS += pth_spinlock endif diff --git a/drd/tests/pth_mutex_signal.c b/drd/tests/pth_mutex_signal.c index ec74696953..38fafdba8a 100644 --- a/drd/tests/pth_mutex_signal.c +++ b/drd/tests/pth_mutex_signal.c @@ -1,4 +1,6 @@ /* + * Verify that pthread_mutex_lock() is not interrupted by a signal. + * * See also https://bugs.kde.org/show_bug.cgi?id=445743. */ @@ -11,7 +13,6 @@ #include #define STACK_SIZE 1024 * 512 -#define NATIVE_IO_INTERRUPT_SIGNAL (SIGRTMAX - 2) #define LONG_SLEEP_TIME 1000000 void *contender_start(void *arg) @@ -47,7 +48,7 @@ int main () signalAction.sa_sigaction = nullHandler; sigfillset(&signalAction.sa_mask); signalAction.sa_flags = 0; - sigaction(NATIVE_IO_INTERRUPT_SIGNAL, &signalAction, NULL); + sigaction(SIGINT, &signalAction, NULL); // initialize the mutex pthread_mutexattr_init(&mutex_attr); @@ -70,14 +71,22 @@ int main () } fprintf(stderr, "thread created\n"); pthread_attr_destroy(&thread_attr_contender); - + + // Block signals in the current thread such that signals are delivered to the + // 'contender' thread. + { + sigset_t mask; + sigfillset(&mask); + pthread_sigmask(SIG_BLOCK, &mask, NULL); + } + // wait until the thread is sleeping inside pthread_mutex_lock(). fprintf(stderr, "sleeping\n"); usleep(LONG_SLEEP_TIME); // signal thread fprintf(stderr, "signalling\n"); - pthread_kill(contender, NATIVE_IO_INTERRUPT_SIGNAL); + pthread_kill(contender, SIGINT); fprintf(stderr, "sleeping\n"); usleep(LONG_SLEEP_TIME);