diff mbox series

[1/5] nptl: Add mutex-internal.h

Message ID 1514559519-13167-1-git-send-email-adhemerval.zanella@linaro.org
State New
Headers show
Series [1/5] nptl: Add mutex-internal.h | expand

Commit Message

Adhemerval Zanella Dec. 29, 2017, 2:58 p.m. UTC
The current way of adding different flags and place a common definition
at sysdeps/nptl/bits/thread-shared-types.h for internal pthread_mutex_t
struct is not really the simpler option for new ports: it requires
some misleading flags that shouldn't be defined any way
(__PTHREAD_COMPAT_PADDING_MID and __PTHREAD_COMPAT_PADDING_END),
it gives an option used solely for linuxthread compat mode that
removes the possibility of using adaptive robust mutexes
(__PTHREAD_MUTEX_USE_UNION), and add a flag
(__PTHREAD_MUTEX_NUSERS_AFTER_KIND) that only exists for compatibility
reason.

Instead this patch adds a new architecture define header meant for
internal pthread_mutex_t type (__pthread_mutex_s) layout definition.
The idea is to simplify new ports inclusion by providing a default
generic interface.

The definions for __pthread_mutex_s internal layout compat mode
(__PTHREAD_COMPAT_PADDING_MID, __PTHREAD_COMPAT_PADDING_END,
__PTHREAD_MUTEX_NUSERS_AFTER_KIND, __PTHREAD_MUTEX_USE_UNION) are
removed and the internal pthread type (__pthread_mutex_s) is move
from pthreadtypes-arch.h to mutex-internal.h.

Also the static intialization macro for pthread_mutex_t is set to use
an arch defined on (__PTHREAD_MUTEX_INITIALIZER) which simplifies its
implementation.

The default pthread_mutex_t layout differs from current ports with:

  1. The internal layout is the same for both 32 bits and 64 bits.

  2. The __spins and __list is not an union for 32 bits.  It allows adaptive
     mutexes to work with robust attribute.  Current code does not support
     for 32 bits it due mutex struct size limitation for compatibility with
     linuxthreads.

  3. It uses a double linked list for robust internal list.  It allows
     faster insertion and removals at the cost of slight more memory
     usage.

Checked with a build on affected abis (alpha-linux-gnu, armv7-linux-gnueabihf,
hppa-linux-gnu, ia64-linux-gnu, i686-linux-gnu, m68k-linux-gnu,
microblaze-linux-gnu, nios2-linux-gnu, powerpc{64le}-linux-gnu,
s390{x}-linux-gnu, sh4-linux-gnu, sparc{v9,64}-linux-gnu,
tile{pro,gx64}-linux-gnu, x86_64-linux-gnu).

	* posix/Makefile (headers): Add mutex-internal.h.
	* sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_COMPAT_PADDING_MID, __PTHREAD_COMPAT_PADDING_END,
	__PTHREAD_MUTEX_LOCK_ELISION, __PTHREAD_MUTEX_NUSERS_AFTER_KIND,
	__PTHREAD_MUTEX_USE_UNION): Move to mutex-interal.h.
	* sysdeps/alpha/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/arm/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/hppa/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/ia64/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/m68k/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/nios2/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/s390/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/sh/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/sparc/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/tile/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/x86/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/arm/nptl/bits/mutex-internal.h: New file.
	* sysdeps/hppa/nptl/bits/mutex-internal.h: Likewise.
	* sysdeps/m68k/nptl/bits/mutex-internal.h: Likewise.
	* sysdeps/microblaze/nptl/bits/mutex-internal.h: Likewise.
	* sysdeps/mips/nptl/bits/mutex-internal.h: Likewise.
	* sysdeps/nios2/nptl/bits/mutex-internal.h: Likewise.
	* sysdeps/nptl/bits/mutex-internal.h: Likewise.
	* sysdeps/powerpc/nptl/bits/mutex-internal.h: Likewise.
	* sysdeps/s390/nptl/bits/mutex-internal.h: Likewise.
	* sysdeps/sh/nptl/bits/mutex-internal.h: Likewise.
	* sysdeps/sparc/nptl/bits/mutex-internal.h: Likewise.
	* sysdeps/tile/nptl/bits/mutex-internal.h: Likewise.
	* sysdeps/x86/nptl/bits/mutex-internal.h: Likewise.
	* sysdeps/nptl/bits/thread-shared-types.h: Include mutex-internal.h.
	* sysdeps/nptl/pthread.h (PTHREAD_MUTEX_INITIALIZER,
	PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
	PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP,
	PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP): Implement based on arch
	specific __PTHREAD_MUTEX_INITIALIZER macro.
	* sysdeps/unix/sysv/linux/hppa/pthread.h: Likewise.

Signed-off-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

---
 ChangeLog                                        |  41 ++++++++
 posix/Makefile                                   |   1 +
 sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h    |   7 --
 sysdeps/alpha/nptl/bits/pthreadtypes-arch.h      |   7 --
 sysdeps/arm/nptl/bits/mutex-internal.h           |  44 +++++++++
 sysdeps/arm/nptl/bits/pthreadtypes-arch.h        |   7 --
 sysdeps/hppa/nptl/bits/mutex-internal.h          |  54 +++++++++++
 sysdeps/hppa/nptl/bits/pthreadtypes-arch.h       |  11 ---
 sysdeps/ia64/nptl/bits/mutex-internal.h          |  41 ++++++++
 sysdeps/ia64/nptl/bits/pthreadtypes-arch.h       |   7 --
 sysdeps/m68k/nptl/bits/mutex-internal.h          |  44 +++++++++
 sysdeps/m68k/nptl/bits/pthreadtypes-arch.h       |   7 --
 sysdeps/microblaze/nptl/bits/mutex-internal.h    |  43 +++++++++
 sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h |   7 --
 sysdeps/mips/nptl/bits/mutex-internal.h          |  58 ++++++++++++
 sysdeps/nios2/nptl/bits/mutex-internal.h         |  44 +++++++++
 sysdeps/nios2/nptl/bits/pthreadtypes-arch.h      |   7 --
 sysdeps/nptl/bits/mutex-internal.h               |  43 +++++++++
 sysdeps/nptl/bits/thread-shared-types.h          | 116 ++++++-----------------
 sysdeps/nptl/pthread.h                           |  33 ++-----
 sysdeps/powerpc/nptl/bits/mutex-internal.h       |  64 +++++++++++++
 sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h    |   7 --
 sysdeps/s390/nptl/bits/mutex-internal.h          |  65 +++++++++++++
 sysdeps/s390/nptl/bits/pthreadtypes-arch.h       |   7 --
 sysdeps/sh/nptl/bits/mutex-internal.h            |  43 +++++++++
 sysdeps/sh/nptl/bits/pthreadtypes-arch.h         |   7 --
 sysdeps/sparc/nptl/bits/mutex-internal.h         |  59 ++++++++++++
 sysdeps/sparc/nptl/bits/pthreadtypes-arch.h      |   7 --
 sysdeps/tile/nptl/bits/mutex-internal.h          |  57 +++++++++++
 sysdeps/tile/nptl/bits/pthreadtypes-arch.h       |   7 --
 sysdeps/unix/sysv/linux/hppa/pthread.h           |  11 +--
 sysdeps/x86/nptl/bits/mutex-internal.h           |  65 +++++++++++++
 sysdeps/x86/nptl/bits/pthreadtypes-arch.h        |  12 ---
 33 files changed, 806 insertions(+), 227 deletions(-)
 create mode 100644 sysdeps/arm/nptl/bits/mutex-internal.h
 create mode 100644 sysdeps/hppa/nptl/bits/mutex-internal.h
 create mode 100644 sysdeps/ia64/nptl/bits/mutex-internal.h
 create mode 100644 sysdeps/m68k/nptl/bits/mutex-internal.h
 create mode 100644 sysdeps/microblaze/nptl/bits/mutex-internal.h
 create mode 100644 sysdeps/mips/nptl/bits/mutex-internal.h
 create mode 100644 sysdeps/nios2/nptl/bits/mutex-internal.h
 create mode 100644 sysdeps/nptl/bits/mutex-internal.h
 create mode 100644 sysdeps/powerpc/nptl/bits/mutex-internal.h
 create mode 100644 sysdeps/s390/nptl/bits/mutex-internal.h
 create mode 100644 sysdeps/sh/nptl/bits/mutex-internal.h
 create mode 100644 sysdeps/sparc/nptl/bits/mutex-internal.h
 create mode 100644 sysdeps/tile/nptl/bits/mutex-internal.h
 create mode 100644 sysdeps/x86/nptl/bits/mutex-internal.h

-- 
2.7.4

Comments

Joseph Myers Jan. 1, 2018, 1:38 a.m. UTC | #1
On Fri, 29 Dec 2017, Adhemerval Zanella wrote:

> Checked with a build on affected abis (alpha-linux-gnu, armv7-linux-gnueabihf,

> hppa-linux-gnu, ia64-linux-gnu, i686-linux-gnu, m68k-linux-gnu,

> microblaze-linux-gnu, nios2-linux-gnu, powerpc{64le}-linux-gnu,

> s390{x}-linux-gnu, sh4-linux-gnu, sparc{v9,64}-linux-gnu,

> tile{pro,gx64}-linux-gnu, x86_64-linux-gnu).


Did you verify that installed stripped shared libraries are unchanged by 
the patch for all those configurations?  I think that's important 
validation to do for a change such as this.  (The same comment applies to 
patch 2 as well.)

-- 
Joseph S. Myers
joseph@codesourcery.com
Adhemerval Zanella Jan. 1, 2018, 12:38 p.m. UTC | #2
On 31/12/2017 23:38, Joseph Myers wrote:
> On Fri, 29 Dec 2017, Adhemerval Zanella wrote:

> 

>> Checked with a build on affected abis (alpha-linux-gnu, armv7-linux-gnueabihf,

>> hppa-linux-gnu, ia64-linux-gnu, i686-linux-gnu, m68k-linux-gnu,

>> microblaze-linux-gnu, nios2-linux-gnu, powerpc{64le}-linux-gnu,

>> s390{x}-linux-gnu, sh4-linux-gnu, sparc{v9,64}-linux-gnu,

>> tile{pro,gx64}-linux-gnu, x86_64-linux-gnu).

> 

> Did you verify that installed stripped shared libraries are unchanged by 

> the patch for all those configurations?  I think that's important 

> validation to do for a change such as this.  (The same comment applies to 

> patch 2 as well.)

> 


No, but I will do the verification.  For mutex types I think the current
static assert checks should be suffice to check for any ABI changes,
while for rwlock I think we should add a static assert for the user
visible flag field.
Adhemerval Zanella Jan. 4, 2018, 6:48 p.m. UTC | #3
On 01/01/2018 10:38, Adhemerval Zanella wrote:
> 

> 

> On 31/12/2017 23:38, Joseph Myers wrote:

>> On Fri, 29 Dec 2017, Adhemerval Zanella wrote:

>>

>>> Checked with a build on affected abis (alpha-linux-gnu, armv7-linux-gnueabihf,

>>> hppa-linux-gnu, ia64-linux-gnu, i686-linux-gnu, m68k-linux-gnu,

>>> microblaze-linux-gnu, nios2-linux-gnu, powerpc{64le}-linux-gnu,

>>> s390{x}-linux-gnu, sh4-linux-gnu, sparc{v9,64}-linux-gnu,

>>> tile{pro,gx64}-linux-gnu, x86_64-linux-gnu).

>>

>> Did you verify that installed stripped shared libraries are unchanged by 

>> the patch for all those configurations?  I think that's important 

>> validation to do for a change such as this.  (The same comment applies to 

>> patch 2 as well.)

>>

> 

> No, but I will do the verification.  For mutex types I think the current

> static assert checks should be suffice to check for any ABI changes,

> while for rwlock I think we should add a static assert for the user

> visible flag field.

> 


I checked the installed stripped shared libraries with and without the
patch I saw changes for ia64-linux-gnu, m68k-linux-gnu, i686-linux-gnu,
and mips64-linux-gnu.  However they are introduced by the __pthread_list_t
and __pthread_slist_t declaration done regardless it will be used by
__pthread_mutex_s (previously they are only declared if the struct
actually used it). If I comment the unrequired one the resulted shared
libraries are unchanged and I think this change should be safe.
diff mbox series

Patch

diff --git a/posix/Makefile b/posix/Makefile
index e34b108..f52a5e0 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -27,6 +27,7 @@  headers	:= sys/utsname.h sys/times.h sys/wait.h sys/types.h unistd.h	      \
 	   getopt.h bits/getopt_core.h bits/getopt_ext.h bits/getopt_posix.h  \
 	   bits/types.h bits/typesizes.h bits/pthreadtypes.h		      \
 	   bits/pthreadtypes-arch.h bits/thread-shared-types.h		      \
+	   bits/mutex-internal.h					      \
 	   bits/posix1_lim.h bits/posix2_lim.h bits/posix_opt.h		      \
 	   bits/local_lim.h tar.h bits/utsname.h bits/confname.h	      \
 	   bits/waitflags.h bits/waitstatus.h sys/unistd.h sched.h	      \
diff --git a/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h b/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
index 9ab23d0..7cf45f0 100644
--- a/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
@@ -41,13 +41,6 @@ 
 #define __SIZEOF_PTHREAD_COND_T         48
 #define __SIZEOF_PTHREAD_RWLOCKATTR_T	8
 
-/* Definitions for internal mutex struct.  */
-#define __PTHREAD_COMPAT_PADDING_MID
-#define __PTHREAD_COMPAT_PADDING_END
-#define __PTHREAD_MUTEX_LOCK_ELISION	0
-#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  0
-#define __PTHREAD_MUTEX_USE_UNION          0
-
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
 
diff --git a/sysdeps/alpha/nptl/bits/pthreadtypes-arch.h b/sysdeps/alpha/nptl/bits/pthreadtypes-arch.h
index 429df10..0d6d7e6 100644
--- a/sysdeps/alpha/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/alpha/nptl/bits/pthreadtypes-arch.h
@@ -29,13 +29,6 @@ 
 #define __SIZEOF_PTHREAD_BARRIER_T	32
 #define __SIZEOF_PTHREAD_BARRIERATTR_T	4
 
-/* Definitions for internal mutex struct.  */
-#define __PTHREAD_COMPAT_PADDING_MID
-#define __PTHREAD_COMPAT_PADDING_END
-#define __PTHREAD_MUTEX_LOCK_ELISION    0
-#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  0
-#define __PTHREAD_MUTEX_USE_UNION          0
-
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
 
diff --git a/sysdeps/arm/nptl/bits/mutex-internal.h b/sysdeps/arm/nptl/bits/mutex-internal.h
new file mode 100644
index 0000000..fc00ebf
--- /dev/null
+++ b/sysdeps/arm/nptl/bits/mutex-internal.h
@@ -0,0 +1,44 @@ 
+/* ARM internal mutex struct definitions.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_MUTEX_INTERNAL_H
+#define _THREAD_MUTEX_INTERNAL_H 1
+
+struct __pthread_mutex_s
+{
+  int __lock;
+  unsigned int __count;
+  int __owner;
+  /* KIND must stay at this position in the structure to maintain
+     binary compatibility with static initializers.  */
+  int __kind;
+  unsigned int __nusers;
+  __extension__ union
+  {
+    int __spins;
+    __pthread_slist_t __list;
+  };
+};
+
+#define __PTHREAD_MUTEX_LOCK_ELISION       0
+#define __PTHREAD_MUTEX_HAVE_PREV          0
+
+#define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, __kind, 0, { 0 }
+
+#endif
diff --git a/sysdeps/arm/nptl/bits/pthreadtypes-arch.h b/sysdeps/arm/nptl/bits/pthreadtypes-arch.h
index 3911c81..ffd8de3 100644
--- a/sysdeps/arm/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/arm/nptl/bits/pthreadtypes-arch.h
@@ -30,13 +30,6 @@ 
 #define __SIZEOF_PTHREAD_BARRIER_T 20
 #define __SIZEOF_PTHREAD_BARRIERATTR_T 4
 
-/* Data structure for mutex handling. */
-#define __PTHREAD_COMPAT_PADDING_MID
-#define __PTHREAD_COMPAT_PADDING_END
-#define __PTHREAD_MUTEX_LOCK_ELISION    0
-#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  1
-#define __PTHREAD_MUTEX_USE_UNION          1
-
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
 
diff --git a/sysdeps/hppa/nptl/bits/mutex-internal.h b/sysdeps/hppa/nptl/bits/mutex-internal.h
new file mode 100644
index 0000000..3368375
--- /dev/null
+++ b/sysdeps/hppa/nptl/bits/mutex-internal.h
@@ -0,0 +1,54 @@ 
+/* HPPA internal mutex struct definitions.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_MUTEX_INTERNAL_H
+#define _THREAD_MUTEX_INTERNAL_H 1
+
+struct __pthread_mutex_s
+{
+  int __lock __LOCK_ALIGNMENT;
+  unsigned int __count;
+  int __owner;
+  /* KIND must stay at this position in the structure to maintain
+     binary compatibility with static initializers.  */
+  int __kind;
+  /* The old 4-word 16-byte aligned lock. This is initalized
+     to all ones by the Linuxthreads PTHREAD_MUTEX_INITIALIZER.
+     Unused in NPTL.  */
+  int __glibc_compat_padding[4];
+  /* In the old structure there are 4 words left due to alignment.
+     In NPTL two words are used.  */
+  unsigned int __nusers;
+  __extension__ union
+  {
+    int __spins;
+    __pthread_slist_t __list;
+  };
+  /* Two more words are left before the NPTL
+     pthread_mutex_t is larger than Linuxthreads.  */
+  int __glibc_reserved1;
+  int __glibc_reserved2;
+};
+
+#define __PTHREAD_MUTEX_LOCK_ELISION    0
+#define __PTHREAD_MUTEX_HAVE_PREV       0
+
+#define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, __kind, { 0, 0, 0, 0 }, 0, { 0 }, 0, 0
+
+#endif
diff --git a/sysdeps/hppa/nptl/bits/pthreadtypes-arch.h b/sysdeps/hppa/nptl/bits/pthreadtypes-arch.h
index 865a14e..cf9399d 100644
--- a/sysdeps/hppa/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/hppa/nptl/bits/pthreadtypes-arch.h
@@ -40,17 +40,6 @@ 
 #define __SIZEOF_PTHREAD_RWLOCK_T 64
 #define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
 
-/* The old 4-word 16-byte aligned lock. This is initalized
-   to all ones by the Linuxthreads PTHREAD_MUTEX_INITIALIZER.
-   Unused in NPTL.  */
-#define __PTHREAD_COMPAT_PADDING_MID  int __compat_padding[4];
-/* Two more words are left before the NPTL
-   pthread_mutex_t is larger than Linuxthreads.  */
-#define __PTHREAD_COMPAT_PADDING_END  int __reserved[2];
-#define __PTHREAD_MUTEX_LOCK_ELISION    0
-#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  1
-#define __PTHREAD_MUTEX_USE_UNION          1
-
 #define __LOCK_ALIGNMENT __attribute__ ((__aligned__(16)))
 #define __ONCE_ALIGNMENT
 
diff --git a/sysdeps/ia64/nptl/bits/mutex-internal.h b/sysdeps/ia64/nptl/bits/mutex-internal.h
new file mode 100644
index 0000000..aef672d
--- /dev/null
+++ b/sysdeps/ia64/nptl/bits/mutex-internal.h
@@ -0,0 +1,41 @@ 
+/* Default internal mutex struct definitions.  ia64 version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_MUTEX_INTERNAL_H
+#define _THREAD_MUTEX_INTERNAL_H 1
+
+struct __pthread_mutex_s
+{
+  int __lock;
+  unsigned int __count;
+  int __owner;
+  unsigned int __nusers;
+  /* KIND must stay at this position in the structure to maintain
+     binary compatibility with static initializers.  */
+  int __kind;
+  int __spins;
+  __pthread_list_t __list;
+};
+
+#define __PTHREAD_MUTEX_HAVE_PREV       1
+#define __PTHREAD_MUTEX_LOCK_ELISION    0
+
+#define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, 0, __kind, 0, { 0, 0 }
+
+#endif
diff --git a/sysdeps/ia64/nptl/bits/pthreadtypes-arch.h b/sysdeps/ia64/nptl/bits/pthreadtypes-arch.h
index 2a3bc75..42c71af 100644
--- a/sysdeps/ia64/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/ia64/nptl/bits/pthreadtypes-arch.h
@@ -29,13 +29,6 @@ 
 #define __SIZEOF_PTHREAD_BARRIER_T 32
 #define __SIZEOF_PTHREAD_BARRIERATTR_T 4
 
-/* Definitions for internal mutex struct.  */
-#define __PTHREAD_COMPAT_PADDING_MID
-#define __PTHREAD_COMPAT_PADDING_END
-#define __PTHREAD_MUTEX_LOCK_ELISION    0
-#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  0
-#define __PTHREAD_MUTEX_USE_UNION          0
-
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
 
diff --git a/sysdeps/m68k/nptl/bits/mutex-internal.h b/sysdeps/m68k/nptl/bits/mutex-internal.h
new file mode 100644
index 0000000..ebfd0ab
--- /dev/null
+++ b/sysdeps/m68k/nptl/bits/mutex-internal.h
@@ -0,0 +1,44 @@ 
+/* m68k internal mutex struct definitions.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_MUTEX_INTERNAL_H
+#define _THREAD_MUTEX_INTERNAL_H 1
+
+struct __pthread_mutex_s
+{
+  int __lock __LOCK_ALIGNMENT;
+  unsigned int __count;
+  int __owner;
+  /* KIND must stay at this position in the structure to maintain
+     binary compatibility with static initializers.  */
+  int __kind;
+  unsigned int __nusers;
+  __extension__ union
+  {
+    int __spins;
+    __pthread_slist_t __list;
+  };
+};
+
+#define __PTHREAD_MUTEX_LOCK_ELISION       0
+#define __PTHREAD_MUTEX_HAVE_PREV          0
+
+#define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, __kind, 0, { 0 }
+
+#endif
diff --git a/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h b/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
index 966cc75..7ff98fe 100644
--- a/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
@@ -31,13 +31,6 @@ 
 #define __SIZEOF_PTHREAD_BARRIER_T 20
 #define __SIZEOF_PTHREAD_BARRIERATTR_T 4
 
-/* Data structure for mutex handling. */
-#define __PTHREAD_COMPAT_PADDING_MID
-#define __PTHREAD_COMPAT_PADDING_END
-#define __PTHREAD_MUTEX_LOCK_ELISION    0
-#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  1
-#define __PTHREAD_MUTEX_USE_UNION          1
-
 #define __LOCK_ALIGNMENT __attribute__ ((__aligned__ (4)))
 #define __ONCE_ALIGNMENT __attribute__ ((__aligned__ (4)))
 
diff --git a/sysdeps/microblaze/nptl/bits/mutex-internal.h b/sysdeps/microblaze/nptl/bits/mutex-internal.h
new file mode 100644
index 0000000..98fda1a
--- /dev/null
+++ b/sysdeps/microblaze/nptl/bits/mutex-internal.h
@@ -0,0 +1,43 @@ 
+/* Microblaze internal mutex struct definitions.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_MUTEX_INTERNAL_H
+#define _THREAD_MUTEX_INTERNAL_H 1
+
+struct __pthread_mutex_s
+{
+  int __lock;
+  unsigned int __count;
+  int __owner;
+  /* KIND must stay at this position in the structure to maintain
+     binary compatibility with static initializers.  */
+  int __kind;
+  unsigned int __nusers;
+  __extension__ union
+  {
+    int __spins;
+    __pthread_slist_t __list;
+  };
+};
+#define __PTHREAD_MUTEX_HAVE_PREV          0
+#define __PTHREAD_MUTEX_LOCK_ELISION       0
+
+#define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, __kind, 0, { 0 }
+
+#endif
diff --git a/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h b/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
index e44f2dc..b69feaa 100644
--- a/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
@@ -31,13 +31,6 @@ 
 # define __SIZEOF_PTHREAD_BARRIER_T      20
 # define __SIZEOF_PTHREAD_BARRIERATTR_T   4
 
-/* Definitions for internal mutex struct.  */
-#define __PTHREAD_COMPAT_PADDING_MID
-#define __PTHREAD_COMPAT_PADDING_END
-#define __PTHREAD_MUTEX_LOCK_ELISION    0
-#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  1
-#define __PTHREAD_MUTEX_USE_UNION          1
-
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
 
diff --git a/sysdeps/mips/nptl/bits/mutex-internal.h b/sysdeps/mips/nptl/bits/mutex-internal.h
new file mode 100644
index 0000000..f76a19a
--- /dev/null
+++ b/sysdeps/mips/nptl/bits/mutex-internal.h
@@ -0,0 +1,58 @@ 
+/* MIPS internal mutex struct definitions.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_MUTEX_INTERNAL_H
+#define _THREAD_MUTEX_INTERNAL_H 1
+
+struct __pthread_mutex_s
+{
+  int __lock;
+  unsigned int __count;
+  int __owner;
+#if _MIPS_SIM == _ABI64
+  unsigned int __nusers;
+#endif
+  /* KIND must stay at this position in the structure to maintain
+     binary compatibility with static initializers.  */
+  int __kind;
+#if _MIPS_SIM == _ABI64
+  int __spins;
+  __pthread_list_t __list;
+# define __PTHREAD_MUTEX_HAVE_PREV      1
+#else
+  unsigned int __nusers;
+  __extension__ union
+  {
+    int __spins;
+    __pthread_slist_t __list;
+  };
+# define __PTHREAD_MUTEX_HAVE_PREV      0
+#endif
+};
+
+#define __PTHREAD_MUTEX_LOCK_ELISION    0
+
+#if _MIPS_SIM == _ABI64
+# define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, 0, __kind, 0, { 0, 0 }
+#else
+# define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, __kind, 0, { 0 }
+#endif
+
+#endif
diff --git a/sysdeps/nios2/nptl/bits/mutex-internal.h b/sysdeps/nios2/nptl/bits/mutex-internal.h
new file mode 100644
index 0000000..5b53f07
--- /dev/null
+++ b/sysdeps/nios2/nptl/bits/mutex-internal.h
@@ -0,0 +1,44 @@ 
+/* NIOS2 internal mutex struct definitions.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_MUTEX_INTERNAL_H
+#define _THREAD_MUTEX_INTERNAL_H 1
+
+struct __pthread_mutex_s
+{
+  int __lock;
+  unsigned int __count;
+  int __owner;
+  /* KIND must stay at this position in the structure to maintain
+     binary compatibility with static initializers.  */
+  int __kind;
+  unsigned int __nusers;
+  __extension__ union
+  {
+    int __spins;
+    __pthread_slist_t __list;
+  };
+};
+
+#define __PTHREAD_MUTEX_LOCK_ELISION       0
+#define __PTHREAD_MUTEX_HAVE_PREV          0
+
+#define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, __kind, 0, { 0 }
+
+#endif
diff --git a/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h b/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
index 83f8684..18ea235 100644
--- a/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
@@ -31,13 +31,6 @@ 
 #define __SIZEOF_PTHREAD_BARRIER_T 20
 #define __SIZEOF_PTHREAD_BARRIERATTR_T 4
 
-/* Data structure for mutex handling. */
-#define __PTHREAD_COMPAT_PADDING_MID
-#define __PTHREAD_COMPAT_PADDING_END
-#define __PTHREAD_MUTEX_LOCK_ELISION    0
-#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  1
-#define __PTHREAD_MUTEX_USE_UNION          1
-
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
 
diff --git a/sysdeps/nptl/bits/mutex-internal.h b/sysdeps/nptl/bits/mutex-internal.h
new file mode 100644
index 0000000..ca938e7
--- /dev/null
+++ b/sysdeps/nptl/bits/mutex-internal.h
@@ -0,0 +1,43 @@ 
+/* Default internal mutex struct definitions.  Linux version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_MUTEX_INTERNAL_H
+#define _THREAD_MUTEX_INTERNAL_H 1
+
+/* This is the default defines for the 'struct __pthread_mutex_s' layout,
+   used for POSIX pthread_mutex_t definition.  New ports are expected to
+   used the default layout.  The struct will have size of 32 on LP32 and
+   40 on LP64.  */
+
+struct __pthread_mutex_s
+{
+   int __lock;
+   unsigned int __count;
+   int __owner;
+   unsigned int __nusers;
+   int __kind;
+   int __spins;
+   __pthread_list_t __list;
+};
+
+#define __PTHREAD_MUTEX_HAVE_PREV         1
+#define __PTHREAD_MUTEX_LOCK_ELISION      0
+#define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, 0, __kind, 0, { 0, 0 }
+
+#endif
diff --git a/sysdeps/nptl/bits/thread-shared-types.h b/sysdeps/nptl/bits/thread-shared-types.h
index da4358a..5bfd54e 100644
--- a/sysdeps/nptl/bits/thread-shared-types.h
+++ b/sysdeps/nptl/bits/thread-shared-types.h
@@ -32,36 +32,6 @@ 
    __SIZEOF_PTHREAD_BARRIER_T     - size of pthread_barrier_t.
    __SIZEOF_PTHREAD_BARRIERATTR_T - size of pthread_barrierattr_t.
 
-   Also, the following macros must be define for internal pthread_mutex_t
-   struct definitions (struct __pthread_mutex_s):
-
-   __PTHREAD_COMPAT_PADDING_MID   - any additional members after 'kind'
-				    and before '__spin' (for 64 bits) or
-				    '__nusers' (for 32 bits).
-   __PTHREAD_COMPAT_PADDING_END   - any additional members at the end of
-				    the internal structure.
-   __PTHREAD_MUTEX_LOCK_ELISION   - 1 if the architecture supports lock
-				    elision or 0 otherwise.
-   __PTHREAD_MUTEX_NUSERS_AFTER_KIND - control where to put __nusers.  The
-				       preferred value for new architectures
-				       is 0.
-   __PTHREAD_MUTEX_USE_UNION      - control whether internal __spins and
-				    __list will be place inside a union for
-				    linuxthreads compatibility.
-				    The preferred value for new architectures
-				    is 0.
-
-   For a new port the preferred values for the required defines are:
-
-   #define __PTHREAD_COMPAT_PADDING_MID
-   #define __PTHREAD_COMPAT_PADDING_END
-   #define __PTHREAD_MUTEX_LOCK_ELISION         0
-   #define __PTHREAD_MUTEX_NUSERS_AFTER_KIND    0
-   #define __PTHREAD_MUTEX_USE_UNION            0
-
-   __PTHREAD_MUTEX_LOCK_ELISION can be set to 1 if the hardware plans to
-   eventually support lock elision using transactional memory.
-
    The additional macro defines any constraint for the lock alignment
    inside the thread structures:
 
@@ -72,78 +42,46 @@ 
    __ONCE_ALIGNMENT - for pthread_once_t/once_flag definition.
 
    And finally the internal pthread_rwlock_t (struct __pthread_rwlock_arch_t)
-   must be defined.
- */
+   must be defined.  */
+
 #include <bits/pthreadtypes-arch.h>
 
+
 /* Common definition of pthread_mutex_t. */
 
-#if !__PTHREAD_MUTEX_USE_UNION
 typedef struct __pthread_internal_list
 {
   struct __pthread_internal_list *__prev;
   struct __pthread_internal_list *__next;
 } __pthread_list_t;
-#else
+
 typedef struct __pthread_internal_slist
 {
   struct __pthread_internal_slist *__next;
 } __pthread_slist_t;
-#endif
-
-/* Lock elision support.  */
-#if __PTHREAD_MUTEX_LOCK_ELISION
-# if !__PTHREAD_MUTEX_USE_UNION
-#  define __PTHREAD_SPINS_DATA	\
-  short __spins;		\
-  short __elision
-#  define __PTHREAD_SPINS             0, 0
-# else
-#  define __PTHREAD_SPINS_DATA	\
-  struct			\
-  {				\
-    short __espins;		\
-    short __eelision;		\
-  } __elision_data
-#  define __PTHREAD_SPINS         { 0, 0 }
-#  define __spins __elision_data.__espins
-#  define __elision __elision_data.__eelision
-# endif
-#else
-# define __PTHREAD_SPINS_DATA int __spins
-/* Mutex __spins initializer used by PTHREAD_MUTEX_INITIALIZER.  */
-# define __PTHREAD_SPINS 0
-#endif
-
-struct __pthread_mutex_s
-{
-  int __lock __LOCK_ALIGNMENT;
-  unsigned int __count;
-  int __owner;
-#if !__PTHREAD_MUTEX_NUSERS_AFTER_KIND
-  unsigned int __nusers;
-#endif
-  /* KIND must stay at this position in the structure to maintain
-     binary compatibility with static initializers.  */
-  int __kind;
-  __PTHREAD_COMPAT_PADDING_MID
-#if __PTHREAD_MUTEX_NUSERS_AFTER_KIND
-  unsigned int __nusers;
-#endif
-#if !__PTHREAD_MUTEX_USE_UNION
-  __PTHREAD_SPINS_DATA;
-  __pthread_list_t __list;
-# define __PTHREAD_MUTEX_HAVE_PREV      1
-#else
-  __extension__ union
-  {
-    __PTHREAD_SPINS_DATA;
-    __pthread_slist_t __list;
-  };
-# define __PTHREAD_MUTEX_HAVE_PREV      0
-#endif
-  __PTHREAD_COMPAT_PADDING_END
-};
+
+/* Arch-specific mutex definitions.  A generic implementation is provided
+   by sysdeps/nptl/bits/mutex-internal.h.  If required, an architecture
+   can override it by defining:
+
+   1. struct __pthread_mutex_s (used on pthread_mutex_t definition).  It
+      should contain at least the internal members defined in the generic
+      version.
+
+   2. __PTHREAD_MUTEX_HAVE_PREV to either 1 if __pthread_mutex_s defines
+      the double-linked list __pthread_internal_list, or 0 if it uses
+      the single-linked list __pthread_internal_slist.  They are used on
+      robust mutex implementation and the double-linked trades memory
+      usage for a faster insertion and removal.
+
+   3. __PTHREAD_MUTEX_LOCK_ELISION to either 1 if architecture supports
+      hardware lock elision and actually uses the __elision member or
+      0 otherwise.
+
+   4. __PTHREAD_MUTEX_INITIALIZER macro used for static initialization.
+      It should initialize the mutex internal type.  */
+
+#include <bits/mutex-internal.h>
 
 
 /* Common definition of pthread_cond_t. */
diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h
index 787ac6e..d4a0aa8 100644
--- a/sysdeps/nptl/pthread.h
+++ b/sysdeps/nptl/pthread.h
@@ -84,30 +84,15 @@  enum
 #endif
 
 
-#if __PTHREAD_MUTEX_HAVE_PREV
-# define PTHREAD_MUTEX_INITIALIZER \
-  { { 0, 0, 0, 0, 0, __PTHREAD_SPINS, { 0, 0 } } }
-# ifdef __USE_GNU
-#  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
-  { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, __PTHREAD_SPINS, { 0, 0 } } }
-#  define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
-  { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, __PTHREAD_SPINS, { 0, 0 } } }
-#  define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
-  { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, __PTHREAD_SPINS, { 0, 0 } } }
-
-# endif
-#else
-# define PTHREAD_MUTEX_INITIALIZER \
-  { { 0, 0, 0, 0, 0, { __PTHREAD_SPINS } } }
-# ifdef __USE_GNU
-#  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
-  { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { __PTHREAD_SPINS } } }
-#  define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
-  { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { __PTHREAD_SPINS } } }
-#  define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
-  { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { __PTHREAD_SPINS } } }
-
-# endif
+#define PTHREAD_MUTEX_INITIALIZER \
+ { {  __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_DEFAULT) } }
+#ifdef __USE_GNU
+# define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
+ { {  __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_RECURSIVE_NP) } }
+# define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
+ { {  __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_ERRORCHECK_NP) } }
+# define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
+ { {  __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_ADAPTIVE_NP) } }
 #endif
 
 
diff --git a/sysdeps/powerpc/nptl/bits/mutex-internal.h b/sysdeps/powerpc/nptl/bits/mutex-internal.h
new file mode 100644
index 0000000..0485a44
--- /dev/null
+++ b/sysdeps/powerpc/nptl/bits/mutex-internal.h
@@ -0,0 +1,64 @@ 
+/* PowerPC internal mutex struct definitions.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_MUTEX_INTERNAL_H
+#define _THREAD_MUTEX_INTERNAL_H 1
+
+struct __pthread_mutex_s
+{
+  int __lock;
+  unsigned int __count;
+  int __owner;
+#if __WORDSIZE == 64
+  unsigned int __nusers;
+#endif
+  /* KIND must stay at this position in the structure to maintain
+     binary compatibility with static initializers.  */
+  int __kind;
+#if __WORDSIZE == 64
+  short __spins;
+  short __elision;
+  __pthread_list_t __list;
+# define __PTHREAD_MUTEX_HAVE_PREV      1
+#else
+  unsigned int __nusers;
+  __extension__ union
+  {
+    struct
+    {
+      short __espins;
+      short __elision;
+# define __spins __elision_data.__espins
+# define __elision __elision_data.__elision
+    } __elision_data;
+    __pthread_slist_t __list;
+  };
+# define __PTHREAD_MUTEX_HAVE_PREV      0
+#endif
+};
+#define __PTHREAD_MUTEX_LOCK_ELISION    1
+
+#if __WORDSIZE == 64
+# define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, 0, __kind, 0, 0, { 0, 0 }
+#else
+# define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, __kind, 0, { { 0, 0 } }
+#endif
+
+#endif
diff --git a/sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h b/sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h
index 8158cb5..3a1680a 100644
--- a/sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h
@@ -38,13 +38,6 @@ 
 #define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
 #define __SIZEOF_PTHREAD_BARRIERATTR_T 4
 
-/* Definitions for internal mutex struct.  */
-#define __PTHREAD_COMPAT_PADDING_MID
-#define __PTHREAD_COMPAT_PADDING_END
-#define __PTHREAD_MUTEX_LOCK_ELISION    1
-#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  (__WORDSIZE != 64)
-#define __PTHREAD_MUTEX_USE_UNION          (__WORDSIZE != 64)
-
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
 
diff --git a/sysdeps/s390/nptl/bits/mutex-internal.h b/sysdeps/s390/nptl/bits/mutex-internal.h
new file mode 100644
index 0000000..f3549bd
--- /dev/null
+++ b/sysdeps/s390/nptl/bits/mutex-internal.h
@@ -0,0 +1,65 @@ 
+/* S390 internal mutex struct definitions.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_MUTEX_INTERNAL_H
+#define _THREAD_MUTEX_INTERNAL_H 1
+
+struct __pthread_mutex_s
+{
+  int __lock;
+  unsigned int __count;
+  int __owner;
+#if __WORDSIZE == 64
+  unsigned int __nusers;
+#endif
+  /* KIND must stay at this position in the structure to maintain
+     binary compatibility with static initializers.  */
+  int __kind;
+#if __WORDSIZE == 64
+  short __spins;
+  short __elision;
+  __pthread_list_t __list;
+# define __PTHREAD_MUTEX_HAVE_PREV      1
+#else
+  unsigned int __nusers;
+  __extension__ union
+  {
+    struct
+    {
+      short __espins;
+      short __elision;
+    } _d;
+#  define __spins _d.__espins
+#  define __elision _d.__elision
+    __pthread_slist_t __list;
+  };
+# define __PTHREAD_MUTEX_HAVE_PREV      0
+#endif
+};
+
+#define __PTHREAD_MUTEX_LOCK_ELISION    1
+
+#if __WORDSIZE == 64
+# define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, 0, __kind, 0, 0, { 0, 0 }
+#else
+# define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, __kind, 0, { { 0, 0 } }
+#endif
+
+#endif
diff --git a/sysdeps/s390/nptl/bits/pthreadtypes-arch.h b/sysdeps/s390/nptl/bits/pthreadtypes-arch.h
index fd15931..6ff0f12 100644
--- a/sysdeps/s390/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/s390/nptl/bits/pthreadtypes-arch.h
@@ -37,13 +37,6 @@ 
 #define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
 #define __SIZEOF_PTHREAD_BARRIERATTR_T 4
 
-/* Definitions for internal mutex struct.  */
-#define __PTHREAD_COMPAT_PADDING_MID
-#define __PTHREAD_COMPAT_PADDING_END
-#define __PTHREAD_MUTEX_LOCK_ELISION    1
-#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  (__WORDSIZE != 64)
-#define __PTHREAD_MUTEX_USE_UNION          (__WORDSIZE != 64)
-
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
 
diff --git a/sysdeps/sh/nptl/bits/mutex-internal.h b/sysdeps/sh/nptl/bits/mutex-internal.h
new file mode 100644
index 0000000..83acf27
--- /dev/null
+++ b/sysdeps/sh/nptl/bits/mutex-internal.h
@@ -0,0 +1,43 @@ 
+/* SH internal mutex struct definitions.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_MUTEX_INTERNAL_H
+#define _THREAD_MUTEX_INTERNAL_H 1
+
+struct __pthread_mutex_s
+{
+  int __lock;
+  unsigned int __count;
+  int __owner;
+  /* KIND must stay at this position in the structure to maintain
+     binary compatibility with static initializers.  */
+  int __kind;
+  unsigned int __nusers;
+  __extension__ union
+  {
+    int __spins;
+    __pthread_slist_t __list;
+  };
+};
+#define __PTHREAD_MUTEX_LOCK_ELISION       0
+#define __PTHREAD_MUTEX_HAVE_PREV          0
+
+#define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, __kind, 0, { 0 }
+
+#endif
diff --git a/sysdeps/sh/nptl/bits/pthreadtypes-arch.h b/sysdeps/sh/nptl/bits/pthreadtypes-arch.h
index e707751..ca28010 100644
--- a/sysdeps/sh/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/sh/nptl/bits/pthreadtypes-arch.h
@@ -30,13 +30,6 @@ 
 #define __SIZEOF_PTHREAD_BARRIER_T 20
 #define __SIZEOF_PTHREAD_BARRIERATTR_T 4
 
-/* Definitions for internal mutex struct.  */
-#define __PTHREAD_COMPAT_PADDING_MID
-#define __PTHREAD_COMPAT_PADDING_END
-#define __PTHREAD_MUTEX_LOCK_ELISION    0
-#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  1
-#define __PTHREAD_MUTEX_USE_UNION          1
-
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
 
diff --git a/sysdeps/sparc/nptl/bits/mutex-internal.h b/sysdeps/sparc/nptl/bits/mutex-internal.h
new file mode 100644
index 0000000..265a067
--- /dev/null
+++ b/sysdeps/sparc/nptl/bits/mutex-internal.h
@@ -0,0 +1,59 @@ 
+/* SPARC internal mutex struct definitions.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_MUTEX_INTERNAL_H
+#define _THREAD_MUTEX_INTERNAL_H 1
+
+struct __pthread_mutex_s
+{ 
+  int __lock;
+  unsigned int __count;
+  int __owner;
+#if __WORDSIZE == 64
+  unsigned int __nusers;
+#endif
+  /* KIND must stay at this position in the structure to maintain
+     binary compatibility with static initializers.  */
+  int __kind;
+#if __WORDSIZE == 64
+  int __spins;
+  __pthread_list_t __list;
+# define __PTHREAD_MUTEX_HAVE_PREV      1
+#else
+  unsigned int __nusers;
+  __extension__ union
+  {
+    int __spins;
+    __pthread_slist_t __list;
+  };
+# define __PTHREAD_MUTEX_HAVE_PREV      0
+#endif
+};
+
+#define __PTHREAD_MUTEX_LOCK_ELISION    0
+
+
+#if __WORDSIZE == 64
+# define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, 0, __kind, 0, { 0, 0 }
+#else
+# define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, __kind, 0, { 0 }
+#endif
+
+#endif
diff --git a/sysdeps/sparc/nptl/bits/pthreadtypes-arch.h b/sysdeps/sparc/nptl/bits/pthreadtypes-arch.h
index 0f96f37..92f1ae2 100644
--- a/sysdeps/sparc/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/sparc/nptl/bits/pthreadtypes-arch.h
@@ -39,13 +39,6 @@ 
 #define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
 #define __SIZEOF_PTHREAD_BARRIERATTR_T 4
 
-/* Definitions for internal mutex struct.  */
-#define __PTHREAD_COMPAT_PADDING_MID
-#define __PTHREAD_COMPAT_PADDING_END
-#define __PTHREAD_MUTEX_LOCK_ELISION    0
-#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  (__WORDSIZE != 64)
-#define __PTHREAD_MUTEX_USE_UNION          (__WORDSIZE != 64)
-
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
 
diff --git a/sysdeps/tile/nptl/bits/mutex-internal.h b/sysdeps/tile/nptl/bits/mutex-internal.h
new file mode 100644
index 0000000..253873d
--- /dev/null
+++ b/sysdeps/tile/nptl/bits/mutex-internal.h
@@ -0,0 +1,57 @@ 
+/* Microblaze internal mutex struct definitions.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_MUTEX_INTERNAL_H
+#define _THREAD_MUTEX_INTERNAL_H 1
+
+struct __pthread_mutex_s
+{ 
+  int __lock;
+  unsigned int __count;
+  int __owner;
+#if __WORDSIZE == 64
+  unsigned int __nusers;
+#endif
+  /* KIND must stay at this position in the structure to maintain
+     binary compatibility with static initializers.  */
+  int __kind;
+#if __WORDSIZE == 64
+  int __spins;
+  __pthread_list_t __list;
+# define __PTHREAD_MUTEX_HAVE_PREV      1
+#else
+  unsigned int __nusers;
+  __extension__ union
+  {
+    int __spins;
+    __pthread_slist_t __list;
+  };
+# define __PTHREAD_MUTEX_HAVE_PREV      0
+#endif
+};
+#define __PTHREAD_MUTEX_LOCK_ELISION    0
+
+#if __WORDSIZE == 64
+# define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, 0, __kind, 0, { 0, 0 }
+#else
+# define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, __kind, 0, { 0 }
+#endif
+
+#endif
diff --git a/sysdeps/tile/nptl/bits/pthreadtypes-arch.h b/sysdeps/tile/nptl/bits/pthreadtypes-arch.h
index 054474f..fef6176 100644
--- a/sysdeps/tile/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/tile/nptl/bits/pthreadtypes-arch.h
@@ -39,13 +39,6 @@ 
 #define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
 #define __SIZEOF_PTHREAD_BARRIERATTR_T 4
 
-/* Data structure for mutex handling. */
-#define __PTHREAD_COMPAT_PADDING_MID
-#define __PTHREAD_COMPAT_PADDING_END
-#define __PTHREAD_MUTEX_LOCK_ELISION    0
-#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  (__WORDSIZE != 64)
-#define __PTHREAD_MUTEX_USE_UNION          (__WORDSIZE != 64)
-
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
 
diff --git a/sysdeps/unix/sysv/linux/hppa/pthread.h b/sysdeps/unix/sysv/linux/hppa/pthread.h
index 3d69ddc..4f01670 100644
--- a/sysdeps/unix/sysv/linux/hppa/pthread.h
+++ b/sysdeps/unix/sysv/linux/hppa/pthread.h
@@ -85,17 +85,14 @@  enum
 
 
 #define PTHREAD_MUTEX_INITIALIZER \
-  { { 0, 0, 0, 0, { 0, 0, 0, 0 }, 0, { __PTHREAD_SPINS }, { 0, 0 } } }
+ { {  __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_DEFAULT) } }
 #ifdef __USE_GNU
 # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
-  { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, { 0, 0, 0, 0 }, 0, \
-      { __PTHREAD_SPINS }, { 0, 0 } } }
+ { {  __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_RECURSIVE_NP) } }
 # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
-  { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, { 0, 0, 0, 0 }, 0, \
-      { __PTHREAD_SPINS }, { 0, 0 } } }
+ { {  __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_ERRORCHECK_NP) } }
 # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
-  { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, { 0, 0, 0, 0 }, 0, \
-      { __PTHREAD_SPINS }, { 0, 0 } } }
+ { {  __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_ADAPTIVE_NP) } }
 #endif
 
 
diff --git a/sysdeps/x86/nptl/bits/mutex-internal.h b/sysdeps/x86/nptl/bits/mutex-internal.h
new file mode 100644
index 0000000..4f54d4d
--- /dev/null
+++ b/sysdeps/x86/nptl/bits/mutex-internal.h
@@ -0,0 +1,65 @@ 
+/* x86 internal mutex struct definitions.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_MUTEX_INTERNAL_H
+#define _THREAD_MUTEX_INTERNAL_H 1
+
+struct __pthread_mutex_s
+{
+  int __lock;
+  unsigned int __count;
+  int __owner;
+#ifdef __x86_64__
+  unsigned int __nusers;
+#endif
+  /* KIND must stay at this position in the structure to maintain
+     binary compatibility with static initializers.  */
+  int __kind;
+#ifdef __x86_64__
+  short __spins;
+  short __elision;
+  __pthread_list_t __list;
+# define __PTHREAD_MUTEX_HAVE_PREV      1
+#else
+  unsigned int __nusers;
+  __extension__ union
+  {
+    struct
+    {
+      short __espins;
+      short __elision;
+# define __spins __elision_data.__espins
+# define __elision __elision_data.__elision
+# define __PTHREAD_SPINS         { 0, 0 }
+    } __elision_data;
+    __pthread_slist_t __list;
+  };
+# define __PTHREAD_MUTEX_HAVE_PREV      0
+#endif
+};
+#define __PTHREAD_MUTEX_LOCK_ELISION    0
+
+#ifdef __x86_64__
+# define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, 0, __kind, 0, 0, { 0, 0 }
+#else
+# define __PTHREAD_MUTEX_INITIALIZER(__kind) \
+  0, 0, 0, __kind, 0, { { 0, 0 } }
+#endif
+
+#endif
diff --git a/sysdeps/x86/nptl/bits/pthreadtypes-arch.h b/sysdeps/x86/nptl/bits/pthreadtypes-arch.h
index 74d5f6d..a2c209b 100644
--- a/sysdeps/x86/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/x86/nptl/bits/pthreadtypes-arch.h
@@ -47,18 +47,6 @@ 
 #define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
 #define __SIZEOF_PTHREAD_BARRIERATTR_T 4
 
-/* Definitions for internal mutex struct.  */
-#define __PTHREAD_COMPAT_PADDING_MID
-#define __PTHREAD_COMPAT_PADDING_END
-#define __PTHREAD_MUTEX_LOCK_ELISION    1
-#ifdef __x86_64__
-# define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  0
-# define __PTHREAD_MUTEX_USE_UNION          0
-#else
-# define __PTHREAD_MUTEX_NUSERS_AFTER_KIND  1
-# define __PTHREAD_MUTEX_USE_UNION          1
-#endif
-
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT