about summary refs log tree commit diff
path: root/sysdeps/x86/nptl/bits
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2017-11-08 09:23:34 -0200
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-11-26 13:53:36 +0000
commit1c3f9acf1f1f75faa7a28bf39af64afda93839ac (patch)
tree41bdee95bb276b6712b2b64e86011613d9cad723 /sysdeps/x86/nptl/bits
parent0377a7fde6dfcc078dda29a1225d7720a0931357 (diff)
downloadglibc-1c3f9acf1f1f75faa7a28bf39af64afda93839ac.tar.gz
glibc-1c3f9acf1f1f75faa7a28bf39af64afda93839ac.tar.xz
glibc-1c3f9acf1f1f75faa7a28bf39af64afda93839ac.zip
nptl: Add struct_mutex.h
The current way of defining the common mutex definition for POSIX and
C11 on pthreadtypes-arch.h (added by commit 06be6368da16104be5) is
not really the best options for newer ports.  It requires define some
misleading flags that should be always defined as 0
(__PTHREAD_COMPAT_PADDING_MID and __PTHREAD_COMPAT_PADDING_END), it
exposes options used solely for linuxthreads compat mode
(__PTHREAD_MUTEX_USE_UNION and __PTHREAD_MUTEX_NUSERS_AFTER_KIND), and
requires newer ports to explicit define them (adding more boilerplate
code).

This patch adds a new default __pthread_mutex_s definition meant to
be used by newer ports.  Its layout mimics the current usage on both
32 and 64 bits ports and it allows most ports to use the generic
definition.  Only ports that use some arch-specific definition (such
as hardware lock-elision or linuxthreads compat) requires specific
headers.

For 32 bit, the generic definitions mimic the other 32-bit ports
of using an union to define the fields uses on adaptive and robust
mutexes (thus not allowing both usage at same time) and by using a
single linked-list for robust mutexes.  Both decisions seemed to
follow what recent ports have done and make the resulting
pthread_mutex_t/mtx_t object smaller.

Also the static intialization macro for pthread_mutex_t is set to use
a macro __PTHREAD_MUTEX_INITIALIZER where the architecture can redefine
in its struct_mutex.h if it requires additional fields to be
initialized.

Checked with a build on affected abis.

Change-Id: I30a22c3e3497805fd6e52994c5925897cffcfe13
Diffstat (limited to 'sysdeps/x86/nptl/bits')
-rw-r--r--sysdeps/x86/nptl/bits/pthreadtypes-arch.h12
-rw-r--r--sysdeps/x86/nptl/bits/struct_mutex.h63
2 files changed, 63 insertions, 12 deletions
diff --git a/sysdeps/x86/nptl/bits/pthreadtypes-arch.h b/sysdeps/x86/nptl/bits/pthreadtypes-arch.h
index 1f05ca088c..668ec4a5d5 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
 
diff --git a/sysdeps/x86/nptl/bits/struct_mutex.h b/sysdeps/x86/nptl/bits/struct_mutex.h
new file mode 100644
index 0000000000..09384487f9
--- /dev/null
+++ b/sysdeps/x86/nptl/bits/struct_mutex.h
@@ -0,0 +1,63 @@
+/* x86 internal mutex struct definitions.
+   Copyright (C) 2019 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 __eelision;
+# define __spins __elision_data.__espins
+# define __elision __elision_data.__eelision
+    } __elision_data;
+    __pthread_slist_t __list;
+  };
+# define __PTHREAD_MUTEX_HAVE_PREV      0
+#endif
+};
+
+#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