about summary refs log tree commit diff
path: root/sysdeps/nptl
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2018-05-10 17:24:56 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-01-03 18:38:16 -0200
commitce7eb0e90315eb1939ac29f656d39b3db858c092 (patch)
tree66f46e348749230c9fb9c95e7d77b01eff8598c9 /sysdeps/nptl
parent0b13e25581afb4ce95373f18249b91c104280a13 (diff)
downloadglibc-ce7eb0e90315eb1939ac29f656d39b3db858c092.tar.gz
glibc-ce7eb0e90315eb1939ac29f656d39b3db858c092.tar.xz
glibc-ce7eb0e90315eb1939ac29f656d39b3db858c092.zip
nptl: Cleanup cancellation macros
This patch wraps all uses of *_{enable,disable}_asynccancel and
and *_CANCEL_{ASYNC,RESET} in either already provided macros
(lll_futex_timed_wait_cancel) or creates new ones if the
functionality is not provided (SYSCALL_CANCEL_NCS, lll_futex_wait_cancel,
and lll_futex_timed_wait_cancel).

Also for some generic implementations, the direct call of the macros
are removed since the underlying symbols are suppose to provide
cancellation support.

This is a priliminary patch intended to simplify the work required
for BZ#12683 fix.  It is a refactor change, no semantic changes are
expected.

Checked on x86_64-linux-gnu and i686-linux-gnu.

	* nptl/pthread_join_common.c (__pthread_timedjoin_ex): Use
	lll_wait_tid with timeout.
	* nptl/sem_wait.c (__old_sem_wait): Use lll_futex_wait_cancel.
	* sysdeps/nptl/aio_misc.h (AIO_MISC_WAIT): Use
	futex_reltimed_wait_cancelable for cancelabla mode.
	* sysdeps/nptl/gai_misc.h (GAI_MISC_WAIT): Likewise.
	* sysdeps/posix/open64.c (__libc_open64): Do not call cancelation
	macros.
	* sysdeps/posix/sigwait.c (__sigwait): Likewise.
	* sysdeps/posix/waitid.c (__sigwait): Likewise.
	* sysdeps/unix/sysdep.h (__SYSCALL_CANCEL_CALL,
	SYSCALL_CANCEL_NCS): New macro.
	* sysdeps/nptl/lowlevellock.h (lll_wait_tid): Add timeout argument.
	(lll_timedwait_tid): Remove macro.
	* sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_wait_tid):
	Likewise.
	(lll_timedwait_tid): Likewise.
	* sysdeps/unix/sysv/linux/sparc/lowlevellock.h (lll_wait_tid):
	Likewise.
	(lll_timedwait_tid): Likewise.
	* sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (lll_wait_tid):
	Likewise.
	(lll_timedwait_tid): Likewise.
	* sysdeps/unix/sysv/linux/clock_nanosleep.c (__clock_nanosleep):
	Use INTERNAL_SYSCALL_CANCEL.
	* sysdeps/unix/sysv/linux/futex-internal.h
	(futex_reltimed_wait_cancelable): Use LIBC_CANCEL_{ASYNC,RESET}
	instead of __pthread_{enable,disable}_asynccancel.
	* sysdeps/unix/sysv/linux/lowlevellock-futex.h
	(lll_futex_wait_cancel): New macro.
Diffstat (limited to 'sysdeps/nptl')
-rw-r--r--sysdeps/nptl/aio_misc.h15
-rw-r--r--sysdeps/nptl/gai_misc.h15
-rw-r--r--sysdeps/nptl/lowlevellock.h40
3 files changed, 30 insertions, 40 deletions
diff --git a/sysdeps/nptl/aio_misc.h b/sysdeps/nptl/aio_misc.h
index 8c10021089..c5d829e47c 100644
--- a/sysdeps/nptl/aio_misc.h
+++ b/sysdeps/nptl/aio_misc.h
@@ -41,15 +41,15 @@
       {									      \
 	pthread_mutex_unlock (&__aio_requests_mutex);			      \
 									      \
-	int oldtype;							      \
-	if (cancel)							      \
-	  oldtype = LIBC_CANCEL_ASYNC ();				      \
-									      \
 	int status;							      \
 	do								      \
 	  {								      \
-	    status = futex_reltimed_wait ((unsigned int *) futexaddr, oldval, \
-					  timeout, FUTEX_PRIVATE);	      \
+	    if (cancel)							      \
+	      status = futex_reltimed_wait_cancelable (			      \
+		(unsigned int *) futexaddr, oldval, timeout, FUTEX_PRIVATE);  \
+	    else							      \
+	      status = futex_reltimed_wait ((unsigned int *) futexaddr,	      \
+		oldval, timeout, FUTEX_PRIVATE);	      		      \
 	    if (status != EAGAIN)					      \
 	      break;							      \
 									      \
@@ -57,9 +57,6 @@
 	  }								      \
 	while (oldval != 0);						      \
 									      \
-	if (cancel)							      \
-	  LIBC_CANCEL_RESET (oldtype);					      \
-									      \
 	if (status == EINTR)						      \
 	  result = EINTR;						      \
 	else if (status == ETIMEDOUT)					      \
diff --git a/sysdeps/nptl/gai_misc.h b/sysdeps/nptl/gai_misc.h
index 5632bad454..a3492c7c48 100644
--- a/sysdeps/nptl/gai_misc.h
+++ b/sysdeps/nptl/gai_misc.h
@@ -42,15 +42,15 @@
       {									      \
 	pthread_mutex_unlock (&__gai_requests_mutex);			      \
 									      \
-	int oldtype;							      \
-	if (cancel)							      \
-	  oldtype = LIBC_CANCEL_ASYNC ();				      \
-									      \
 	int status;							      \
 	do								      \
 	  {								      \
-	    status = futex_reltimed_wait ((unsigned int *) futexaddr, oldval, \
-					  timeout, FUTEX_PRIVATE);	      \
+	    if (cancel)							      \
+	      status = futex_reltimed_wait_cancelable (			      \
+		(unsigned int *) futexaddr, oldval, timeout, FUTEX_PRIVATE);  \
+	    else							      \
+	      status = futex_reltimed_wait ((unsigned int *) futexaddr,	      \
+		oldval, timeout, FUTEX_PRIVATE);	      		      \
 	    if (status != EAGAIN)					      \
 	      break;							      \
 									      \
@@ -58,9 +58,6 @@
 	  }								      \
 	while (oldval != 0);						      \
 									      \
-	if (cancel)							      \
-	  LIBC_CANCEL_RESET (oldtype);					      \
-									      \
 	if (status == EINTR)						      \
 	  result = EINTR;						      \
 	else if (status == ETIMEDOUT)					      \
diff --git a/sysdeps/nptl/lowlevellock.h b/sysdeps/nptl/lowlevellock.h
index 45dc1ea470..36bbc472e7 100644
--- a/sysdeps/nptl/lowlevellock.h
+++ b/sysdeps/nptl/lowlevellock.h
@@ -175,33 +175,29 @@ extern int __lll_timedlock_wait (int *futex, const struct timespec *,
 #define LLL_LOCK_INITIALIZER		(0)
 #define LLL_LOCK_INITIALIZER_LOCKED	(1)
 
+extern int __lll_timedwait_tid (int *, const struct timespec *)
+     attribute_hidden;
 
 /* The kernel notifies a process which uses CLONE_CHILD_CLEARTID via futex
    wake-up when the clone terminates.  The memory location contains the
    thread ID while the clone is running and is reset to zero by the kernel
    afterwards.  The kernel up to version 3.16.3 does not use the private futex
-   operations for futex wake-up when the clone terminates.  */
-#define lll_wait_tid(tid)				\
-  do {							\
-    __typeof (tid) __tid;				\
-    /* We need acquire MO here so that we synchronize	\
-       with the kernel's store to 0 when the clone	\
-       terminates. (see above)  */			\
-    while ((__tid = atomic_load_acquire (&(tid))) != 0)	\
-      lll_futex_wait (&(tid), __tid, LLL_SHARED);	\
-  } while (0)
-
-extern int __lll_timedwait_tid (int *, const struct timespec *)
-     attribute_hidden;
-
-/* As lll_wait_tid, but with a timeout.  If the timeout occurs then return
-   ETIMEDOUT.  If ABSTIME is invalid, return EINVAL.  */
-#define lll_timedwait_tid(tid, abstime) \
-  ({							\
-    int __res = 0;					\
-    if ((tid) != 0)					\
-      __res = __lll_timedwait_tid (&(tid), (abstime));	\
-    __res;						\
+   operations for futex wake-up when the clone terminates.
+   If ABSTIME is not NULL, is used a timeout for futex call.  If the timeout
+   occurs then return ETIMEOUT, if ABSTIME is invalid, return EINVAL.
+   The futex operation are issues with cancellable versions.  */
+#define lll_wait_tid(tid, abstime)					\
+  ({									\
+    int __res = 0;							\
+    __typeof (tid) __tid;						\
+    if (abstime != NULL)						\
+      __res = __lll_timedwait_tid (&(tid), (abstime));			\
+    else								\
+      /* We need acquire MO here so that we synchronize with the 	\
+	 kernel's store to 0 when the clone terminates. (see above)  */	\
+      while ((__tid = atomic_load_acquire (&(tid))) != 0)		\
+        lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED);		\
+    __res;								\
   })