]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
drd/tests/pth_mutex_signal: Port to Darwin
authorBart Van Assche <bvanassche@acm.org>
Sun, 29 Jan 2023 22:42:17 +0000 (14:42 -0800)
committerBart Van Assche <bvanassche@acm.org>
Sun, 29 Jan 2023 23:26:11 +0000 (15:26 -0800)
This patch includes a revert of commit 2e873534bb49 ("macOS: drd
pth_mutex_signal test doesn't build").

drd/tests/Makefile.am
drd/tests/pth_mutex_signal.c

index 157bedcf4843fc0d9b406bdf19fa131ee436c840..e3366a18a01fbeeea7b3f69f7a1950fdd9d56184 100755 (executable)
@@ -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
index ec746969537d2a33b00f6405adf408777f16d42d..38fafdba8ad8297498c3e280b1443fe1b17e1344 100644 (file)
@@ -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 <unistd.h>
 
 #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);