[00/11] nptl: pthread cancellation refactor

Message ID 20210526165728.1772546-1-adhemerval.zanella@linaro.org
Headers
Series nptl: pthread cancellation refactor |

Message

Adhemerval Zanella Netto May 26, 2021, 4:57 p.m. UTC
  This patchset refactor and simplifies the nptl cancellation code.
The first 4 patches just add NFC changes and a new test.

The 5th patch fixes an memory leak issue when pthread_create fails to
setup either the scheduling or affinity parameter.  The asynchronous
cancellation is removed in favor of using a member to indicate the
setup has failed and letting the created thread to deallocate the
memory (similar on how detached threads do).

The 6h patch move the signal handler setup to pthread_cancel, now that
asynchronous cancellation is not used anymore on thread creation.

The 7th remove the CANCELING_BITMASK bit, since it is mainly used to
signal that a syscall that has returned should be cancelled (which is
a wrong assumption, since syscall with side-effects should *not* be
cancelled as per BZ#12683).

The 8th and 9th patches move both the cancel state and cancel type out
of 'cancelhandling' variable, since with CANCELING_BITMASK and
pthread_cancel change in previous patch they are not accessed in a
concurrent manner.

The 10th patch consolidates the raise as 'pthread_kill(pthread_self())'.

Finally, the 11th patch uses pthread_kill on pthread_cancel.

Adhemerval Zanella (11):
  nptl: Move Linux createthread to nptl
  nptl: Move createthread to pthread_create
  support: Add xpthread_attr_setaffinity_np wrapper
  nptl: Add pthread_attr_setaffinity_np failure test
  nptl: Deallocate the thread stack on setup failure (BZ #19511)
  nptl: Install cancellation handler on pthread_cancel
  nptl: Remove CANCELING_BITMASK
  nptl: Move cancel state out of cancelhandling
  nptl: Move cancel type out of cancelhandling
  nptl: Implement raise in terms of pthread_kill
  nptl: Use pthread_kill on pthread_cancel

 include/pthread.h                      |   5 +
 manual/pattern.texi                    |   1 -
 manual/process.texi                    |   3 +-
 nptl/Makefile                          |   1 +
 nptl/Versions                          |   3 +-
 nptl/allocatestack.c                   |   3 +
 nptl/cancellation.c                    |  62 ++--------
 nptl/cleanup_defer.c                   |  46 +-------
 nptl/createthread.c                    |  45 --------
 nptl/descr.h                           |  32 ++----
 nptl/libc-cleanup.c                    |  46 +-------
 nptl/pthreadP.h                        |  24 +---
 nptl/pthread_cancel.c                  | 145 ++++++++---------------
 nptl/pthread_create.c                  | 151 ++++++++++++++++++------
 nptl/pthread_join_common.c             |   7 +-
 nptl/pthread_kill.c                    |  52 ++++++---
 nptl/pthread_self.c                    |   4 +-
 nptl/pthread_setcancelstate.c          |  36 +-----
 nptl/pthread_setcanceltype.c           |  41 +------
 nptl/pthread_testcancel.c              |  11 +-
 nptl/tst-pthread-attr-affinity-fail.c  |  54 +++++++++
 support/Makefile                       |   1 +
 support/xpthread_attr_setaffinity_np.c |  28 +++++
 support/xthread.h                      |   3 +
 sysdeps/htl/pthreadP.h                 |   2 -
 sysdeps/posix/raise.c                  |  11 +-
 sysdeps/unix/sysv/linux/createthread.c | 153 -------------------------
 sysdeps/unix/sysv/linux/raise.c        |  52 ---------
 28 files changed, 369 insertions(+), 653 deletions(-)
 delete mode 100644 nptl/createthread.c
 create mode 100644 nptl/tst-pthread-attr-affinity-fail.c
 create mode 100644 support/xpthread_attr_setaffinity_np.c
 delete mode 100644 sysdeps/unix/sysv/linux/createthread.c
 delete mode 100644 sysdeps/unix/sysv/linux/raise.c