From patchwork Wed Nov 6 17:49:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 178748 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp947701ilf; Wed, 6 Nov 2019 09:50:48 -0800 (PST) X-Google-Smtp-Source: APXvYqzQpy+kBETFHnIF4/cTSIJIuBui4X8ISIQ9IQb5Ob5CXOgujGtuI6o+PgRhTYSu2lqlit/J X-Received: by 2002:a50:bb48:: with SMTP id y66mr4164501ede.66.1573062648821; Wed, 06 Nov 2019 09:50:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573062648; cv=none; d=google.com; s=arc-20160816; b=g1p50KTe1LTzgjsX/e+5rocnMcXIUJaOFyeEP28hQA2mV597FZu6zlFFoFsTr3xsQx /hSGFvl3u1mKFCCCmouyWc71NTFn/EUmee1+Srwc3BB6e+Udrthh12K0SY3EV2xG5QtS +EcJIsDPpCOGOJtI6hJP8ypO2XluO5gZ/VJ4Gasc3m3QZ5aMAlzrjBg5UaLvffKOBNvP MsEQMcD2mQQvTtKBjXetS4sMLtDgWIJbUpvQ7cAhCAJrExarj/briYmuWcFM2u+EvS8r wGEcTgtq2+Yx/fzs6nYgaIBMhSHWyCU1vc6Z9RRHKjo0dqzLp821spqbrwYEotYtkSel VVFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=me/Izla0Izp9NjaS2tRXA5O5DlOw9uUgS53+HRwcBH4=; b=I476/4YC/LE/rC6oq62ts+SVQDy5T0Jj4hWjdlRbBct019Fw+awuZ0/FesWwljHcOt X20JN4IS0Fx87/Gi9GsK9pB8YGZVXrvHc3J1xs0AQ/E0yxgdYAjjCrFc7CrRAnjDh2pW /gltMC02w0FkdgIw0hoV5hp3RqX9K7eGVIvKVinrEsRq2wGfV3FgdlfN+FO37c4gaMUm 7bZ3X9NLs4i8/UTBe5Jp8lSdUCOBL/tNlbadInZ7dijeHImyGeTXkpigFQEzLFKrelsO KZFhjCauStuZdySM8pBdqecKDzd2oM6G+W6sziSTpFzVkUL0vAo/NnGV1juSz3XZuQto e5BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=htkmQKcD; dkim=pass header.i=@linaro.org header.s=google header.b=mX9+UYZ2; spf=pass (google.com: domain of libc-alpha-return-106711-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-106711-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id d10si14830139edk.122.2019.11.06.09.50.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Nov 2019 09:50:48 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-106711-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=htkmQKcD; dkim=pass header.i=@linaro.org header.s=google header.b=mX9+UYZ2; spf=pass (google.com: domain of libc-alpha-return-106711-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-106711-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=UYafUZ9/yABK/AUSL9scE/tYxjwky/e wCBBDfUOw9A2vldZqfcQQ3AwwvnFJ/0atWl2TnW7KIm0qURbhd7amKoBvP3j3SOv 7sgyYxhUw9AVGyMN+pkS8UvT29vIFh8pohh0oHQUzOqpFXhwRdWTp2+Tq9dGWxfr goCMdYP4KahQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=iPABOOdJMxvXO0x/ZRnvIcYW8NQ=; b=htkmQ KcD/4HbBI5WIvrsfusJDcAwxANutDXAF1f/eLz2+k9LXIkuERYFUVnnTxNJifu6X K9djVOL+6gbEsJ/ujasNevbGmn8b9dFto/O2xK2PPXw0YvFdoTNHsM6vOskyrWJG Cwp92GG8zUZ/83wiZVXOyqPnTMCb8QQLosBpXQ= Received: (qmail 53643 invoked by alias); 6 Nov 2019 17:50:19 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 53537 invoked by uid 89); 6 Nov 2019 17:50:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=adaptive, LP64 X-HELO: mail-qt1-f193.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=me/Izla0Izp9NjaS2tRXA5O5DlOw9uUgS53+HRwcBH4=; b=mX9+UYZ2iwTzUewBWyk8PyOEeFwwQWadcD9U8V4JtPUbMT6tBNZBy/fwsEUSanGNo0 uDiBeMqtgnRbBQkk0UdxLcLHbhzr8rWTPzM+staKF0XDqWuYSG0GMWrScRuv5oScZbce h8Vmzy2F8a7e4ZxeiT9+2XeU8/RBhB+sWE9Zx55L3Rws/UOppCY10+NmIae/07joffVm GP8BOpSk0NNcFI+2Qk2s3GPfvy0anBwY/4/qSErRv2gUwJKd/mmwZql4BoIONMqv82Vw +D7f9uS6Z7kZ2JHj5sX1hM9KNGqEMdKbCuxtQekhqq2EV6SCnDE+yZ9RfiEEJ4gntxFz ug0w== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 3/7] nptl: Add mutex-internal.h Date: Wed, 6 Nov 2019 14:49:57 -0300 Message-Id: <20191106175001.12182-3-adhemerval.zanella@linaro.org> In-Reply-To: <20191106175001.12182-1-adhemerval.zanella@linaro.org> References: <20191106175001.12182-1-adhemerval.zanella@linaro.org> 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 mimic the current usage on both 32 and 64 bits ports and it allows most ports use the generic definition. Only ports that use some arch-specific definition (such as hardware lock-elision or linuxthread compat) requires specific headers. For 32 bits, the generic definitions mimics the other 32 bits 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 has 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 an arch defined on (__PTHREAD_MUTEX_INITIALIZER) which simplifies its implementation. Checked with a build on affected abis. --- nptl/Makefile | 3 +- sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h | 7 - sysdeps/alpha/nptl/bits/pthreadtypes-arch.h | 7 - sysdeps/arm/nptl/bits/pthreadtypes-arch.h | 7 - sysdeps/csky/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/pthreadtypes-arch.h | 7 - sysdeps/m68k/nptl/bits/pthreadtypes-arch.h | 7 - .../microblaze/nptl/bits/pthreadtypes-arch.h | 7 - sysdeps/mips/nptl/bits/mutex-internal.h | 58 ++++++++ sysdeps/mips/nptl/bits/pthreadtypes-arch.h | 7 - sysdeps/nios2/nptl/bits/pthreadtypes-arch.h | 7 - sysdeps/nptl/bits/mutex-internal.h | 85 +++++++++++ sysdeps/nptl/bits/thread-shared-types.h | 136 ++++-------------- sysdeps/nptl/pthread.h | 33 ++--- sysdeps/powerpc/nptl/bits/mutex-internal.h | 64 +++++++++ sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h | 7 - sysdeps/riscv/nptl/bits/pthreadtypes-arch.h | 6 - sysdeps/s390/nptl/bits/mutex-internal.h | 65 +++++++++ sysdeps/s390/nptl/bits/pthreadtypes-arch.h | 7 - sysdeps/sh/nptl/bits/pthreadtypes-arch.h | 7 - sysdeps/sparc/nptl/bits/pthreadtypes-arch.h | 7 - sysdeps/unix/sysv/linux/hppa/pthread.h | 11 +- sysdeps/x86/nptl/bits/mutex-internal.h | 64 +++++++++ sysdeps/x86/nptl/bits/pthreadtypes-arch.h | 12 -- 26 files changed, 432 insertions(+), 261 deletions(-) create mode 100644 sysdeps/hppa/nptl/bits/mutex-internal.h create mode 100644 sysdeps/mips/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/x86/nptl/bits/mutex-internal.h -- 2.17.1 diff --git a/nptl/Makefile b/nptl/Makefile index f9aadfd644..f7e3766e3c 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -22,7 +22,8 @@ subdir := nptl include ../Makeconfig -headers := pthread.h semaphore.h bits/semaphore.h threads.h +headers := pthread.h semaphore.h bits/semaphore.h threads.h \ + bits/mutex-internal.h extra-libs := libpthread extra-libs-others := $(extra-libs) diff --git a/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h b/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h index 61c02e7bbc..78abd6960b 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 f5b7d1940e..b832590d82 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/pthreadtypes-arch.h b/sysdeps/arm/nptl/bits/pthreadtypes-arch.h index a2c550f62a..5ae7d0d721 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/csky/nptl/bits/pthreadtypes-arch.h b/sysdeps/csky/nptl/bits/pthreadtypes-arch.h index c1656ae2f6..685515724f 100644 --- a/sysdeps/csky/nptl/bits/pthreadtypes-arch.h +++ b/sysdeps/csky/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/hppa/nptl/bits/mutex-internal.h b/sysdeps/hppa/nptl/bits/mutex-internal.h new file mode 100644 index 0000000000..0a30beef84 --- /dev/null +++ b/sysdeps/hppa/nptl/bits/mutex-internal.h @@ -0,0 +1,54 @@ +/* HPPA 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 + . */ + +#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 7c97b89d60..c11add1af8 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/pthreadtypes-arch.h b/sysdeps/ia64/nptl/bits/pthreadtypes-arch.h index 8eb1bd5ebe..7a1fd3ed28 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/pthreadtypes-arch.h b/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h index cefce56593..0647c48b5a 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/pthreadtypes-arch.h b/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h index 00b50df227..21b090aaf6 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 0000000000..9124b3081c --- /dev/null +++ b/sysdeps/mips/nptl/bits/mutex-internal.h @@ -0,0 +1,58 @@ +/* MIPS 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 + . */ + +#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/mips/nptl/bits/pthreadtypes-arch.h b/sysdeps/mips/nptl/bits/pthreadtypes-arch.h index 629cd72048..5bcc90a7fe 100644 --- a/sysdeps/mips/nptl/bits/pthreadtypes-arch.h +++ b/sysdeps/mips/nptl/bits/pthreadtypes-arch.h @@ -38,13 +38,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 (_MIPS_SIM != _ABI64) -#define __PTHREAD_MUTEX_USE_UNION (_MIPS_SIM != _ABI64) - #define __LOCK_ALIGNMENT #define __ONCE_ALIGNMENT diff --git a/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h b/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h index bba904bcc4..7e71f723d0 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 0000000000..c6100cb118 --- /dev/null +++ b/sysdeps/nptl/bits/mutex-internal.h @@ -0,0 +1,85 @@ +/* Default internal mutex struct definitions. Linux version. + 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 + . */ + +#ifndef _THREAD_MUTEX_INTERNAL_H +#define _THREAD_MUTEX_INTERNAL_H 1 + +/* Generic struct for both POSIX and C11 mutexes. New ports are expected + to use the default layout, however architecture can redefine it to + add arch-specific extension (such as lock-elision). The struct have + a size of 32 bytes on LP32 and 40 bytes on LP64 architectures. */ + +struct __pthread_mutex_s +{ + int __lock __LOCK_ALIGNMENT; + 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. + + Concurrency notes: + The __kind of a mutex is initialized either by the static + PTHREAD_MUTEX_INITIALIZER or by a call to pthread_mutex_init. + + After a mutex has been initialized, the __kind of a mutex is usually not + changed. BUT it can be set to -1 in pthread_mutex_destroy or elision can + be enabled. This is done concurrently in the pthread_mutex_*lock + functions by using the macro FORCE_ELISION. This macro is only defined + for architectures which supports lock elision. + + For elision, there are the flags PTHREAD_MUTEX_ELISION_NP and + PTHREAD_MUTEX_NO_ELISION_NP which can be set in addition to the already + set type of a mutex. Before a mutex is initialized, only + PTHREAD_MUTEX_NO_ELISION_NP can be set with pthread_mutexattr_settype. + + After a mutex has been initialized, the functions pthread_mutex_*lock can + enable elision - if the mutex-type and the machine supports it - by + setting the flag PTHREAD_MUTEX_ELISION_NP. This is done concurrently. + Afterwards the lock / unlock functions are using specific elision + code-paths. */ + int __kind; +#if __WORDSIZE != 64 + unsigned int __nusers; +#endif +#if __WORDSIZE == 64 + int __spins; + __pthread_list_t __list; +# define __PTHREAD_MUTEX_HAVE_PREV 1 +#else + __extension__ union + { + int __spins; + __pthread_slist_t __list; + }; +# define __PTHREAD_MUTEX_HAVE_PREV 0 +#endif +}; + +#define __PTHREAD_MUTEX_LOCK_ELISION 0 +#if __PTHREAD_MUTEX_HAVE_PREV == 1 +# define __PTHREAD_MUTEX_INITIALIZER(__kind) \ + 0, 0, 0, 0, __kind, 0, { 0, 0 } +#else +# define __PTHREAD_MUTEX_INITIALIZER(__kind) \ + 0, 0, 0, 0, __kind, { 0 } +#endif + +#endif diff --git a/sysdeps/nptl/bits/thread-shared-types.h b/sysdeps/nptl/bits/thread-shared-types.h index f7eb8d4c5d..6bfaa79ca1 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,98 +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 + /* 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. - - Concurrency notes: - The __kind of a mutex is initialized either by the static - PTHREAD_MUTEX_INITIALIZER or by a call to pthread_mutex_init. - - After a mutex has been initialized, the __kind of a mutex is usually not - changed. BUT it can be set to -1 in pthread_mutex_destroy or elision can - be enabled. This is done concurrently in the pthread_mutex_*lock functions - by using the macro FORCE_ELISION. This macro is only defined for - architectures which supports lock elision. - - For elision, there are the flags PTHREAD_MUTEX_ELISION_NP and - PTHREAD_MUTEX_NO_ELISION_NP which can be set in addition to the already set - type of a mutex. - Before a mutex is initialized, only PTHREAD_MUTEX_NO_ELISION_NP can be set - with pthread_mutexattr_settype. - After a mutex has been initialized, the functions pthread_mutex_*lock can - enable elision - if the mutex-type and the machine supports it - by setting - the flag PTHREAD_MUTEX_ELISION_NP. This is done concurrently. Afterwards - the lock / unlock functions are using specific elision code-paths. */ - 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 /* Common definition of pthread_cond_t. */ diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h index f2b21accbc..e673e3f4fc 100644 --- a/sysdeps/nptl/pthread.h +++ b/sysdeps/nptl/pthread.h @@ -83,30 +83,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 0000000000..6695efe9d0 --- /dev/null +++ b/sysdeps/powerpc/nptl/bits/mutex-internal.h @@ -0,0 +1,64 @@ +/* PowerPC 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 + . */ + +#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 9810aab057..429d42d77d 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/riscv/nptl/bits/pthreadtypes-arch.h b/sysdeps/riscv/nptl/bits/pthreadtypes-arch.h index 77b60bf8f7..31f46ecbde 100644 --- a/sysdeps/riscv/nptl/bits/pthreadtypes-arch.h +++ b/sysdeps/riscv/nptl/bits/pthreadtypes-arch.h @@ -35,12 +35,6 @@ # error "rv32i-based systems are not supported" #endif -#define __PTHREAD_COMPAT_PADDING_MID -#define __PTHREAD_COMPAT_PADDING_END -#define __PTHREAD_MUTEX_LOCK_ELISION 0 -#define __PTHREAD_MUTEX_USE_UNION 0 -#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND 0 - #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 0000000000..79c732ebe4 --- /dev/null +++ b/sysdeps/s390/nptl/bits/mutex-internal.h @@ -0,0 +1,65 @@ +/* S390 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 + . */ + +#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 1cb1d7216a..5fd32ba756 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/pthreadtypes-arch.h b/sysdeps/sh/nptl/bits/pthreadtypes-arch.h index e7bbfe1861..ec861133ca 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/pthreadtypes-arch.h b/sysdeps/sparc/nptl/bits/pthreadtypes-arch.h index 47093a57a2..4cda2376d2 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/unix/sysv/linux/hppa/pthread.h b/sysdeps/unix/sysv/linux/hppa/pthread.h index 300c187759..3d1e7f3a45 100644 --- a/sysdeps/unix/sysv/linux/hppa/pthread.h +++ b/sysdeps/unix/sysv/linux/hppa/pthread.h @@ -83,17 +83,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 0000000000..376bc679fd --- /dev/null +++ b/sysdeps/x86/nptl/bits/mutex-internal.h @@ -0,0 +1,64 @@ +/* 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 + . */ + +#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 +}; +#define __PTHREAD_MUTEX_LOCK_ELISION 1 + +#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 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