about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-12-20 06:34:59 +0000
committerUlrich Drepper <drepper@redhat.com>2003-12-20 06:34:59 +0000
commit4efdd8d355a378ab85278bef1c00c05c46ab49e4 (patch)
tree2711786af8a2b51279bfefbe3acb481bd45e2e6b
parent8a7455e70db36c00281a31f60e899d6b424e732b (diff)
downloadglibc-4efdd8d355a378ab85278bef1c00c05c46ab49e4.tar.gz
glibc-4efdd8d355a378ab85278bef1c00c05c46ab49e4.tar.xz
glibc-4efdd8d355a378ab85278bef1c00c05c46ab49e4.zip
Update.
2003-12-19  Ulrich Drepper  <drepper@redhat.com>

	* eintr.c (setup_eintr): Add new parameter.  Pass to thread function.
	(eintr_source): If ARG != NULL, use pthread_kill.
	* tst-eintr1.c: Adjust for this change.
	* tst-eintr2.c: Likewise.
	* Makefile (tests): Add tst-eintr3 and tst-eintr4.
	* tst-eintr3.c: New file.
	* tst-eintr4.c: New file.

2003-12-19  Jakub Jelinek  <jakub@redhat.com>

	* libc-cancellation.c (__libc_enable_asynccancel): Don't cancel
	if CANCELSTATE_BITMASK is set.
	* sysdeps/pthread/librt-cancellation.c (__librt_enable_asynccancel):
	Likewise.

	* Makefile (tests): Add tst-cancel22 and tst-cancel23.
	(tests-reverse): Add tst-cancel23.
	* tst-cancel22.c: New test.
	* tst-cancel23.c: New test.
-rw-r--r--nptl/ChangeLog22
-rw-r--r--nptl/Makefile6
-rw-r--r--nptl/eintr.c9
-rw-r--r--nptl/libc-cancellation.c5
-rw-r--r--nptl/sysdeps/pthread/librt-cancellation.c5
-rw-r--r--nptl/tst-cancel22.c121
-rw-r--r--nptl/tst-cancel23.c1
-rw-r--r--nptl/tst-eintr1.c2
-rw-r--r--nptl/tst-eintr2.c2
-rw-r--r--nptl/tst-eintr3.c72
-rw-r--r--nptl/tst-eintr4.c56
11 files changed, 289 insertions, 12 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog
index de71eb6917..83d6635c25 100644
--- a/nptl/ChangeLog
+++ b/nptl/ChangeLog
@@ -1,3 +1,25 @@
+2003-12-19  Ulrich Drepper  <drepper@redhat.com>
+
+	* eintr.c (setup_eintr): Add new parameter.  Pass to thread function.
+	(eintr_source): If ARG != NULL, use pthread_kill.
+	* tst-eintr1.c: Adjust for this change.
+	* tst-eintr2.c: Likewise.
+	* Makefile (tests): Add tst-eintr3 and tst-eintr4.
+	* tst-eintr3.c: New file.
+	* tst-eintr4.c: New file.
+
+2003-12-19  Jakub Jelinek  <jakub@redhat.com>
+
+	* libc-cancellation.c (__libc_enable_asynccancel): Don't cancel
+	if CANCELSTATE_BITMASK is set.
+	* sysdeps/pthread/librt-cancellation.c (__librt_enable_asynccancel):
+	Likewise.
+
+	* Makefile (tests): Add tst-cancel22 and tst-cancel23.
+	(tests-reverse): Add tst-cancel23.
+	* tst-cancel22.c: New test.
+	* tst-cancel23.c: New test.
+
 2003-12-18  Ulrich Drepper  <drepper@redhat.com>
 
 	* tst-eintr1.c: Better error messages.
diff --git a/nptl/Makefile b/nptl/Makefile
index 91d43d85ee..6876768d93 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -207,7 +207,7 @@ tests = tst-attr1 tst-attr2 tst-attr3 \
 	tst-kill1 tst-kill2 tst-kill3 tst-kill4 tst-kill5 tst-kill6 \
 	tst-join1 tst-join2 tst-join3 tst-join4 tst-join5 \
 	tst-detach1 \
-	tst-eintr1 tst-eintr2 \
+	tst-eintr1 tst-eintr2 tst-eintr3 tst-eintr4 \
 	tst-tsd1 tst-tsd2 tst-tsd3 tst-tsd4 \
 	tst-tls1 tst-tls2 \
 	tst-fork1 tst-fork2 tst-fork3 tst-fork4 \
@@ -216,7 +216,7 @@ tests = tst-attr1 tst-attr2 tst-attr3 \
 	tst-cancel6 tst-cancel7 tst-cancel8 tst-cancel9 tst-cancel10 \
 	tst-cancel11 tst-cancel12 tst-cancel13 tst-cancel14 tst-cancel15 \
 	tst-cancel16 tst-cancel17 tst-cancel18 tst-cancel19 tst-cancel20 \
-	tst-cancel21 \
+	tst-cancel21 tst-cancel22 tst-cancel23 \
 	tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3 tst-cleanup4 \
 	tst-flock1 tst-flock2 \
 	tst-signal1 tst-signal2 tst-signal3 tst-signal4 tst-signal5 \
@@ -326,7 +326,7 @@ ifeq ($(build-static),yes)
 tests-static += tst-locale1 tst-locale2
 endif
 # These tests are linked with libc before libpthread
-tests-reverse += tst-cancel5
+tests-reverse += tst-cancel5 tst-cancel23
 
 include ../Rules
 
diff --git a/nptl/eintr.c b/nptl/eintr.c
index 64e5690981..9e5d6af09a 100644
--- a/nptl/eintr.c
+++ b/nptl/eintr.c
@@ -44,7 +44,10 @@ eintr_source (void *arg)
 
   while (1)
     {
-      kill (getpid (), the_sig);
+      if (arg != NULL)
+	pthread_kill (*(pthread_t *) arg, the_sig);
+      else
+	kill (getpid (), the_sig);
 
       nanosleep (&ts, NULL);
     }
@@ -55,7 +58,7 @@ eintr_source (void *arg)
 
 
 static void
-setup_eintr (int sig)
+setup_eintr (int sig, pthread_t *thp)
 {
   struct sigaction sa;
   sigemptyset (&sa.sa_mask);
@@ -70,7 +73,7 @@ setup_eintr (int sig)
 
   /* Create the thread which will fire off the signals.  */
   pthread_t th;
-  if (pthread_create (&th, NULL, eintr_source, NULL) != 0)
+  if (pthread_create (&th, NULL, eintr_source, thp) != 0)
     {
       puts ("setup_eintr: pthread_create failed");
       exit (1);
diff --git a/nptl/libc-cancellation.c b/nptl/libc-cancellation.c
index a68ee71450..c9237e0950 100644
--- a/nptl/libc-cancellation.c
+++ b/nptl/libc-cancellation.c
@@ -42,8 +42,9 @@ __libc_enable_asynccancel (void)
 
       if (__builtin_expect ((oldval & CANCELED_BITMASK) != 0, 0))
 	{
-	  /* If we are already exiting stop right here.  */
-	  if ((oldval & EXITING_BITMASK) != 0)
+	  /* If we are already exiting or if PTHREAD_CANCEL_DISABLED,
+	     stop right here.  */
+	  if ((oldval & (EXITING_BITMASK | CANCELSTATE_BITMASK)) != 0)
 	    break;
 
 	  int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
diff --git a/nptl/sysdeps/pthread/librt-cancellation.c b/nptl/sysdeps/pthread/librt-cancellation.c
index ae9dd2ad97..753a2d831e 100644
--- a/nptl/sysdeps/pthread/librt-cancellation.c
+++ b/nptl/sysdeps/pthread/librt-cancellation.c
@@ -41,8 +41,9 @@ __librt_enable_asynccancel (void)
 
       if (__builtin_expect ((oldval & CANCELED_BITMASK) != 0, 0))
 	{
-	  /* If we are already exiting stop right here.  */
-	  if ((oldval & EXITING_BITMASK) != 0)
+	  /* If we are already exiting or if PTHREAD_CANCEL_DISABLED,
+	     stop right here.  */
+	  if ((oldval & (EXITING_BITMASK | CANCELSTATE_BITMASK)) != 0)
 	    break;
 
 	  int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
diff --git a/nptl/tst-cancel22.c b/nptl/tst-cancel22.c
new file mode 100644
index 0000000000..33bfc64a3b
--- /dev/null
+++ b/nptl/tst-cancel22.c
@@ -0,0 +1,121 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+pthread_barrier_t b;
+int seen;
+
+static void *
+tf (void *arg)
+{
+  int old;
+  int r = pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &old);
+  if (r != 0)
+    {
+      puts ("setcancelstate failed");
+      exit (1);
+    }
+
+  r = pthread_barrier_wait (&b);
+  if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+    {
+      puts ("barrier_wait failed");
+      exit (1);
+    }
+
+  for (int i = 0; i < 10; ++i)
+    {
+      struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
+      TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
+    }
+
+  seen = 1;
+  pthread_setcancelstate (old, NULL);
+
+  struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
+  TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
+
+  exit (1);
+}
+
+
+static int
+do_test (void)
+{
+  if (pthread_barrier_init (&b, NULL, 2) != 0)
+   {
+     puts ("barrier init failed");
+     return 1;
+   }
+
+  pthread_t th;
+  if (pthread_create (&th, NULL, tf, NULL) != 0)
+    {
+      puts ("thread creation failed");
+      return 1;
+    }
+
+  int r = pthread_barrier_wait (&b);
+  if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+    {
+      puts ("barrier_wait failed");
+      return 1;
+    }
+
+  if (pthread_cancel (th) != 0)
+    {
+      puts ("cancel failed");
+      return 1;
+    }
+
+  void *status;
+  if (pthread_join (th, &status) != 0)
+    {
+      puts ("join failed");
+      return 1;
+    }
+  if (status != PTHREAD_CANCELED)
+    {
+      puts ("thread not canceled");
+      return 1;
+    }
+
+  if (pthread_barrier_destroy (&b) != 0)
+    {
+      puts ("barrier_destroy failed");
+      return 1;
+    }
+
+  if (seen != 1)
+    {
+      puts ("thread cancelled when PTHREAD_CANCEL_DISABLED");
+      return 1;
+    }
+
+  return 0;
+}
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/nptl/tst-cancel23.c b/nptl/tst-cancel23.c
new file mode 100644
index 0000000000..211168748e
--- /dev/null
+++ b/nptl/tst-cancel23.c
@@ -0,0 +1 @@
+#include "tst-cancel22.c"
diff --git a/nptl/tst-eintr1.c b/nptl/tst-eintr1.c
index 41ec2508e0..43a5df5b92 100644
--- a/nptl/tst-eintr1.c
+++ b/nptl/tst-eintr1.c
@@ -77,7 +77,7 @@ tf1 (void *arg)
 static int
 do_test (void)
 {
-  setup_eintr (SIGUSR1);
+  setup_eintr (SIGUSR1, NULL);
 
   int i;
   for (i = 0; i < 10; ++i)
diff --git a/nptl/tst-eintr2.c b/nptl/tst-eintr2.c
index 00b2ecdfcd..410c56ccaf 100644
--- a/nptl/tst-eintr2.c
+++ b/nptl/tst-eintr2.c
@@ -84,7 +84,7 @@ do_test (void)
       exit (1);
     }
 
-  setup_eintr (SIGUSR1);
+  setup_eintr (SIGUSR1, NULL);
 
   pthread_t th;
   char buf[100];
diff --git a/nptl/tst-eintr3.c b/nptl/tst-eintr3.c
new file mode 100644
index 0000000000..eecab48b14
--- /dev/null
+++ b/nptl/tst-eintr3.c
@@ -0,0 +1,72 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "eintr.c"
+
+
+static void *
+tf (void *arg)
+{
+  pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+  pthread_mutex_lock (&m);
+  /* This call must not return.  */
+  pthread_mutex_lock (&m);
+
+  puts ("tf: mutex_lock returned");
+  exit (1);
+}
+
+
+static int
+do_test (void)
+{
+  pthread_t self = pthread_self ();
+
+  setup_eintr (SIGUSR1, &self);
+
+  pthread_t th;
+  char buf[100];
+  int e = pthread_create (&th, NULL, tf, NULL);
+  if (e != 0)
+    {
+      printf ("main: pthread_create failed: %s\n",
+	      strerror_r (e, buf, sizeof (buf)));
+      exit (1);
+    }
+
+  /* This call must never return.  */
+  e = pthread_join (th, NULL);
+
+  if (e == EINTR)
+    puts ("pthread_join returned with EINTR");
+
+  return 0;
+}
+
+#define EXPECTED_SIGNAL SIGALRM
+#define TIMEOUT 1
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/nptl/tst-eintr4.c b/nptl/tst-eintr4.c
new file mode 100644
index 0000000000..dffbdd6052
--- /dev/null
+++ b/nptl/tst-eintr4.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "eintr.c"
+
+
+static int
+do_test (void)
+{
+  pthread_t self = pthread_self ();
+
+  setup_eintr (SIGUSR1, &self);
+
+  pthread_barrier_t b;
+  if (pthread_barrier_init (&b, NULL, 2) != 0)
+    {
+      puts ("barrier_init failed");
+      exit (1);
+    }
+
+  /* This call must never return.  */
+  int e = pthread_barrier_wait (&b);
+
+  if (e == EINTR)
+    puts ("pthread_join returned with EINTR");
+
+  return 0;
+}
+
+#define EXPECTED_SIGNAL SIGALRM
+#define TIMEOUT 1
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"