From: Jonathan Wakely <jwakely@redhat.com>
To: Christophe LYON <christophe.lyon@foss.st.com>
Cc: "libstdc++" <libstdc++@gcc.gnu.org>,
gcc Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v3] libstdc++: Improve std::lock algorithm
Date: Wed, 23 Jun 2021 11:11:14 +0100 [thread overview]
Message-ID: <CACb0b4mXdQNsEHn=LJZVE4gFdFkSyqo=dGfCtkzVKN12U-8T5g@mail.gmail.com> (raw)
In-Reply-To: <095419ad-9d7e-9110-3a25-90fbeec92d45@foss.st.com>
[-- Attachment #1: Type: text/plain, Size: 2319 bytes --]
On Wed, 23 Jun 2021 at 10:43, Christophe LYON wrote:
>
>
> On 23/06/2021 11:17, Jonathan Wakely via Libstdc++ wrote:
> > On Wed, 23 Jun 2021 at 08:21, Christophe Lyon wrote:
> >> This patch causes GCC build failures for bare-metal targets
> >> (aarch64-elf, arm-eabi). For instance on arm-eabi, I'm seeing:
> >>
> >> In file included from
> >> /tmp/1229695_7.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-eabi/gcc3/arm-none-eabi/libstdc++-v3/include/future:38,
> >> from
> >> /tmp/1229695_7.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/include/precompiled/stdc++.h:105:
> >> /tmp/1229695_7.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-eabi/gcc3/arm-none-eabi/libstdc++-v3/include/mutex:
> >> In function 'int std::__detail::__try_lock_impl(_Lockable&)':
> >> /tmp/1229695_7.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-eabi/gcc3/arm-none-eabi/libstdc++-v3/include/mutex:522:53:
> >> error: expected primary-expression before ',' token
> >> 522 | if (unique_lock<_Lockable> __lock{__lockable, try_to_lock})
> >> | ^
> >> In file included from
> >> /tmp/1229695_7.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-eabi/gcc3/arm-none-eabi/libstdc++-v3/include/future:38,
> >> from
> >> /tmp/1229695_7.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/include/precompiled/stdc++.h:105:
> >> /tmp/1229695_7.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-eabi/gcc3/arm-none-eabi/libstdc++-v3/include/mutex:
> >> In function 'int std::__detail::__try_lock_impl(_Lockable&)':
> >> /tmp/1229695_7.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-eabi/gcc3/arm-none-eabi/libstdc++-v3/include/mutex:522:53:
> >> error: expected primary-expression before ',' token
> >> 522 | if (unique_lock<_Lockable> __lock{__lockable, try_to_lock})
> >> | ^
> >> make[4]: *** [Makefile:1862:
> >> arm-none-eabi/bits/stdc++.h.gch/O2ggnu++0x.gch] Error 1
> > Sigh, __lockable is a macro in newlib:
> >
> > newlib/libc/include/sys/cdefs.h:#define __lockable
> > __lock_annotate(lockable)
> >
> > I'll change the name.
>
> Thanks (sorry for being back ;-)
Fixed with this patch, tested x86_64 and pushed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2785 bytes --]
commit 75404109dce57d2f8dac0f90808010233928418f
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Jun 23 11:05:51 2021
libstdc++: Avoid "__lockable" name defined as macro by newlib
libstdc++-v3/ChangeLog:
* include/std/mutex (__detail::__try_lock_impl): Rename
parameter to avoid clashing with newlib's __lockable macro.
(try_lock): Add 'inline' specifier.
* testsuite/17_intro/names.cc: Add check for __lockable.
* testsuite/30_threads/try_lock/5.cc: Add options for pthreads.
diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index c18ca1a1955..eeb51fdb840 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -517,9 +517,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Lock the last lockable, after all previous ones are locked.
template<typename _Lockable>
inline int
- __try_lock_impl(_Lockable& __lockable)
+ __try_lock_impl(_Lockable& __l)
{
- if (unique_lock<_Lockable> __lock{__lockable, try_to_lock})
+ if (unique_lock<_Lockable> __lock{__l, try_to_lock})
{
__lock.release();
return -1;
@@ -585,7 +585,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* Sequentially calls try_lock() on each argument.
*/
template<typename _L1, typename _L2, typename... _L3>
- int
+ inline int
try_lock(_L1& __l1, _L2& __l2, _L3&... __l3)
{
return __detail::__try_lock_impl(__l1, __l2, __l3...);
diff --git a/libstdc++-v3/testsuite/17_intro/names.cc b/libstdc++-v3/testsuite/17_intro/names.cc
index 624e3ed9ccf..534dab70ff5 100644
--- a/libstdc++-v3/testsuite/17_intro/names.cc
+++ b/libstdc++-v3/testsuite/17_intro/names.cc
@@ -16,6 +16,7 @@
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
+// { dg-add-options no_pch }
// Define macros for some common variables names that we must not use for
// naming variables, parameters etc. in the library.
@@ -216,6 +217,11 @@
#undef y
#endif
+#if ! __has_include(<newlib.h>)
+// newlib's <sys/cdefs.h> defines __lockable as a macro, so we can't use it.
+# define __lockable cannot be used as an identifier
+#endif
+
#ifdef __sun__
// See https://gcc.gnu.org/ml/libstdc++/2019-05/msg00175.html
#undef ptr
diff --git a/libstdc++-v3/testsuite/30_threads/try_lock/5.cc b/libstdc++-v3/testsuite/30_threads/try_lock/5.cc
index a5574ff01fb..b9ce1cc9b90 100644
--- a/libstdc++-v3/testsuite/30_threads/try_lock/5.cc
+++ b/libstdc++-v3/testsuite/30_threads/try_lock/5.cc
@@ -1,4 +1,7 @@
-// { dg-do run { target c++11 } }
+// { dg-do run }
+// { dg-additional-options "-pthread" { target pthread } }
+// { dg-require-effective-target c++11 }
+// { dg-require-gthreads "" }
#include <mutex>
#include <testsuite_hooks.h>
next prev parent reply other threads:[~2021-06-23 10:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-21 17:31 [committed] " Jonathan Wakely
2021-06-22 9:07 ` Matthias Kretz
2021-06-22 12:51 ` [PATCH v2] " Jonathan Wakely
2021-06-22 13:21 ` Matthias Kretz
2021-06-22 15:20 ` Jonathan Wakely
2021-06-22 16:03 ` Matthias Kretz
2021-06-22 19:51 ` Jonathan Wakely
2021-06-22 20:32 ` [PATCH v3] " Jonathan Wakely
2021-06-23 7:21 ` Christophe Lyon
2021-06-23 9:17 ` Jonathan Wakely
2021-06-23 9:43 ` Christophe LYON
2021-06-23 10:11 ` Jonathan Wakely [this message]
2021-06-23 11:16 ` Christophe LYON
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACb0b4mXdQNsEHn=LJZVE4gFdFkSyqo=dGfCtkzVKN12U-8T5g@mail.gmail.com' \
--to=jwakely@redhat.com \
--cc=christophe.lyon@foss.st.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).