[8/8] nptl: Use pthread_kill on pthread_cancel
Commit Message
It consolidates the tgkill call and it is the first step of making
pthread_cancel async-signal-safe.
Checked on x86_64-linux-gnu.
---
nptl/Versions | 2 ++
nptl/pthreadP.h | 2 ++
nptl/pthread_cancel.c | 7 +------
nptl/pthread_kill.c | 19 +++++++++++++------
4 files changed, 18 insertions(+), 12 deletions(-)
@@ -66,6 +66,8 @@ libc {
__pthread_attr_copy;
__pthread_getattr_default_np;
__pthread_attr_setsigmask_internal;
+ # Used for thread cancellation.
+ __pthread_kill_internal;
}
}
@@ -514,6 +514,8 @@ extern int __pthread_equal (pthread_t thread1, pthread_t thread2);
extern int __pthread_detach (pthread_t th);
extern int __pthread_cancel (pthread_t th);
libc_hidden_proto (__pthread_kill)
+extern int __pthread_kill_internal (pthread_t threadid, int signo);
+libc_hidden_proto (__pthread_kill_internal);
extern void __pthread_exit (void *value) __attribute__ ((__noreturn__));
extern int __pthread_join (pthread_t threadid, void **thread_return);
extern int __pthread_setcanceltype (int type, int *oldtype);
@@ -69,12 +69,7 @@ __pthread_cancel (pthread_t th)
/* The cancellation handler will take care of marking the
thread as canceled. */
- pid_t pid = __getpid ();
-
- int val = INTERNAL_SYSCALL_CALL (tgkill, pid, pd->tid,
- SIGCANCEL);
- if (INTERNAL_SYSCALL_ERROR_P (val))
- result = INTERNAL_SYSCALL_ERRNO (val);
+ __pthread_kill_internal (th, SIGCANCEL);
break;
}
@@ -20,13 +20,8 @@
#include <pthreadP.h>
int
-__pthread_kill (pthread_t threadid, int signo)
+__pthread_kill_internal (pthread_t threadid, int signo)
{
- /* Disallow sending the signal we use for cancellation, timers,
- for the setxid implementation. */
- if (__is_internal_signal (signo))
- return EINVAL;
-
sigset_t set;
__libc_signal_block_all (&set);
@@ -57,5 +52,17 @@ __pthread_kill (pthread_t threadid, int signo)
return val;
}
+libc_hidden_def (__pthread_kill_internal)
+
+int
+__pthread_kill (pthread_t threadid, int signo)
+{
+ /* Disallow sending the signal we use for cancellation, timers,
+ for the setxid implementation. */
+ if (__is_internal_signal (signo))
+ return EINVAL;
+
+ return __pthread_kill_internal (threadid, signo);
+}
libc_hidden_def (__pthread_kill)
weak_alias (__pthread_kill, pthread_kill)