From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25385 invoked by alias); 11 Jul 2012 05:58:39 -0000 Received: (qmail 25323 invoked by uid 22791); 11 Jul 2012 05:58:33 -0000 X-SWARE-Spam-Status: No, hits=-4.6 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,TW_EQ X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Jul 2012 05:58:17 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1SopwG-0005M6-4P from Maxim_Kuvyrkov@mentor.com ; Tue, 10 Jul 2012 22:58:16 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 10 Jul 2012 22:57:22 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.1.289.1; Wed, 11 Jul 2012 06:58:13 +0100 Subject: [PATCH] Unify pthread_spin_[try]lock implementations. MIME-Version: 1.0 (Apple Message framework v1278) Content-Type: text/plain; charset="us-ascii" From: Maxim Kuvyrkov In-Reply-To: Date: Wed, 11 Jul 2012 05:58:00 -0000 CC: Richard Sandiford , , libc-alpha Devel Content-Transfer-Encoding: quoted-printable Message-ID: <65B470D2-4D01-4BA1-AEC5-A72C0006EA22@codesourcery.com> References: <2109EAD5-BBE8-4C8C-8D61-0AF33290F240@codesourcery.com> To: Joseph S.Myers Mailing-List: contact libc-ports-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: libc-ports-owner@sourceware.org X-SW-Source: 2012-07/txt/msg00020.txt.bz2 On 29/06/2012, at 11:10 AM, Joseph S. Myers wrote: >> diff --git a/sysdeps/mips/nptl/pthread_spin_trylock.c b/sysdeps/mips/npt= l/pthread_spin_trylock.c >> new file mode 100644 >> index 0000000..ed75813 >> --- /dev/null >> +++ b/sysdeps/mips/nptl/pthread_spin_trylock.c >=20 > This file looks generic and essentially the same as the ARM and M68K=20 > versions. I think it would be better to put such a generic version in a= =20 > generic directory (maybe directly in nptl/), and remove the ARM and M68K= =20 > copies, rather than adding a third copy of the same generic=20 > implementation. Indeed. The attached patches for glibc proper and ports unify pthread_spin= _lock and pthread_spin_trylock for ARM, HPPA, M68K and MIPS. I've tested t= hese on MIPS, and the changes for other targets are only mechanical. Any comments? -- Maxim Kuvyrkov CodeSourcery / Mentor Graphics Add generic versions of pthread_spin_lock and pthread_spin_trylock. 2012-07-09 Maxim Kuvyrkov * nptl/pthread_spin_lock.c: New file. * nptl/pthread_spin_trylock.c: New file. --- nptl/pthread_spin_lock.c | 30 ++++++++++++++++++++++++++++++ nptl/pthread_spin_trylock.c | 27 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 0 deletions(-) create mode 100644 nptl/pthread_spin_lock.c create mode 100644 nptl/pthread_spin_trylock.c diff --git a/nptl/pthread_spin_lock.c b/nptl/pthread_spin_lock.c new file mode 100644 index 0000000..1daa43d --- /dev/null +++ b/nptl/pthread_spin_lock.c @@ -0,0 +1,30 @@ +/* pthread_spin_lock -- lock a spin lock. Generic version. + Copyright (C) 2012 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 + . */ + +#include +#include "pthreadP.h" + +int +pthread_spin_lock (pthread_spinlock_t *lock) +{ + while (atomic_compare_and_exchange_val_acq (lock, 1, 0) !=3D 0) + while (*lock !=3D 0) + ; + + return 0; +} diff --git a/nptl/pthread_spin_trylock.c b/nptl/pthread_spin_trylock.c new file mode 100644 index 0000000..a097a86 --- /dev/null +++ b/nptl/pthread_spin_trylock.c @@ -0,0 +1,27 @@ +/* pthread_spin_trylock -- trylock a spin lock. Generic version. + Copyright (C) 2012 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 + . */ + +#include +#include +#include "pthreadP.h" + +int +pthread_spin_trylock (pthread_spinlock_t *lock) +{ + return atomic_compare_and_exchange_val_acq (lock, 1, 0) ? EBUSY : 0; +} --=20 1.7.4.1 Unify ARM, HPPA, M68K and MIPS pthread_spin_lock and pthread_spin_trylock. 2012-06-13 Maxim Kuvyrkov * sysdeps/arm/nptl/pthread_spin_lock.c: Remove, use generic version. * sysdeps/arm/nptl/pthread_spin_trylock.c: Same. * sysdeps/hppa/nptl/pthread_spin_lock.c: Same. * sysdeps/hppa/nptl/pthread_spin_trylock.c: Same. * sysdeps/m68k/nptl/pthread_spin_lock.c: Same. * sysdeps/m68k/nptl/pthread_spin_trylock.c: Same. * sysdeps/mips/nptl/pthread_spin_lock.S: Same. * sysdeps/mips/nptl/pthread_spin_trylock.S: Same. --- sysdeps/arm/nptl/pthread_spin_lock.c | 29 --------------------- sysdeps/arm/nptl/pthread_spin_trylock.c | 26 ------------------- sysdeps/hppa/nptl/pthread_spin_lock.c | 37 --------------------------- sysdeps/hppa/nptl/pthread_spin_trylock.c | 33 ------------------------ sysdeps/m68k/nptl/pthread_spin_lock.c | 30 ---------------------- sysdeps/m68k/nptl/pthread_spin_trylock.c | 27 -------------------- sysdeps/mips/nptl/pthread_spin_lock.S | 36 --------------------------- sysdeps/mips/nptl/pthread_spin_trylock.S | 40 --------------------------= ---- 8 files changed, 0 insertions(+), 258 deletions(-) delete mode 100644 sysdeps/arm/nptl/pthread_spin_lock.c delete mode 100644 sysdeps/arm/nptl/pthread_spin_trylock.c delete mode 100644 sysdeps/hppa/nptl/pthread_spin_lock.c delete mode 100644 sysdeps/hppa/nptl/pthread_spin_trylock.c delete mode 100644 sysdeps/m68k/nptl/pthread_spin_lock.c delete mode 100644 sysdeps/m68k/nptl/pthread_spin_trylock.c delete mode 100644 sysdeps/mips/nptl/pthread_spin_lock.S delete mode 100644 sysdeps/mips/nptl/pthread_spin_trylock.S diff --git a/sysdeps/arm/nptl/pthread_spin_lock.c b/sysdeps/arm/nptl/pthrea= d_spin_lock.c deleted file mode 100644 index 3a23bd3..0000000 --- a/sysdeps/arm/nptl/pthread_spin_lock.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 2008 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 - . */ - -#include -#include "pthreadP.h" - -int -pthread_spin_lock (pthread_spinlock_t *lock) -{ - while (atomic_compare_and_exchange_val_acq (lock, 1, 0) !=3D 0) - while (*lock !=3D 0) - ; - - return 0; -} diff --git a/sysdeps/arm/nptl/pthread_spin_trylock.c b/sysdeps/arm/nptl/pth= read_spin_trylock.c deleted file mode 100644 index 7d31180..0000000 --- a/sysdeps/arm/nptl/pthread_spin_trylock.c +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright (C) 2008 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 - . */ - -#include -#include -#include "pthreadP.h" - -int -pthread_spin_trylock (pthread_spinlock_t *lock) -{ - return atomic_compare_and_exchange_val_acq (lock, 1, 0) ? EBUSY : 0; -} diff --git a/sysdeps/hppa/nptl/pthread_spin_lock.c b/sysdeps/hppa/nptl/pthr= ead_spin_lock.c deleted file mode 100644 index bcf2240..0000000 --- a/sysdeps/hppa/nptl/pthread_spin_lock.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (C) 2005 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 - . */ - -#include -#include "pthreadP.h" - -int -pthread_spin_lock (pthread_spinlock_t *lock) -{ -#if 0 - volatile unsigned int *addr =3D __ldcw_align (lock); - - while (__ldcw (addr) =3D=3D 0) - while (*addr =3D=3D 0) ; - - return 0; -#endif - - while (atomic_compare_and_exchange_val_acq(lock, 1, 0) =3D=3D 1) - while (*lock =3D=3D 1); -=20=20 - return 0; -} diff --git a/sysdeps/hppa/nptl/pthread_spin_trylock.c b/sysdeps/hppa/nptl/p= thread_spin_trylock.c deleted file mode 100644 index a8028610..0000000 --- a/sysdeps/hppa/nptl/pthread_spin_trylock.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (C) 2005 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 - . */ - -#include -#include -#include "pthreadP.h" - -int -pthread_spin_trylock (pthread_spinlock_t *lock) -{ -#if 0 - volatile unsigned int *a =3D __ldcw_align (lock); - - return __ldcw (a) ? 0 : EBUSY; -#endif - - return atomic_compare_and_exchange_val_acq(lock, 1, 0) ? EBUSY : 0; - -} diff --git a/sysdeps/m68k/nptl/pthread_spin_lock.c b/sysdeps/m68k/nptl/pthr= ead_spin_lock.c deleted file mode 100644 index 90a8262..0000000 --- a/sysdeps/m68k/nptl/pthread_spin_lock.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 2010 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Maxim Kuvyrkov , 2010. - - 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 - . */ - -#include -#include "pthreadP.h" - -int -pthread_spin_lock (pthread_spinlock_t *lock) -{ - while (atomic_compare_and_exchange_val_acq(lock, 1, 0) !=3D 0) - while (*lock !=3D 0) - ; - - return 0; -} diff --git a/sysdeps/m68k/nptl/pthread_spin_trylock.c b/sysdeps/m68k/nptl/p= thread_spin_trylock.c deleted file mode 100644 index f4b0c0d..0000000 --- a/sysdeps/m68k/nptl/pthread_spin_trylock.c +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright (C) 2010 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Maxim Kuvyrkov , 2010. - - 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 - . */ - -#include -#include -#include "pthreadP.h" - -int -pthread_spin_trylock (pthread_spinlock_t *lock) -{ - return atomic_compare_and_exchange_val_acq(lock, 1, 0) ? EBUSY : 0; -} diff --git a/sysdeps/mips/nptl/pthread_spin_lock.S b/sysdeps/mips/nptl/pthr= ead_spin_lock.S deleted file mode 100644 index a8504f1..0000000 --- a/sysdeps/mips/nptl/pthread_spin_lock.S +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 2005 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 - . */ - -#include -#include -#include - -ENTRY (pthread_spin_lock) - .set push -#if _MIPS_SIM =3D=3D _ABIO32 - .set mips2 -#endif -1: ll a2, 0(a0) - li a1, 1 - bnez a2, 1b - sc a1, 0(a0) - beqz a1, 1b - MIPS_SYNC - .set pop - li v0, 0 - ret -PSEUDO_END (pthread_spin_lock) diff --git a/sysdeps/mips/nptl/pthread_spin_trylock.S b/sysdeps/mips/nptl/p= thread_spin_trylock.S deleted file mode 100644 index 95b55c3..0000000 --- a/sysdeps/mips/nptl/pthread_spin_trylock.S +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) 2005 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 - . */ - -#include -#include -#define _ERRNO_H 1 -#include -#include - -ENTRY (pthread_spin_trylock) - .set push -#if _MIPS_SIM =3D=3D _ABIO32 - .set mips2 -#endif - ll a2, 0(a0) - li a1, 1 - bnez a2, 1f - sc a1, 0(a0) - beqz a1, 1f - MIPS_SYNC - .set pop - li v0, 0 - ret -1: li v0, EBUSY - ret -PSEUDO_END (pthread_spin_trylock) --=20 1.7.4.1