This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/70463] always use first element of mutex pool in src/c++11/shared_ptr.cc


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70463

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2016-04-05
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This would shift the address right to remove the bits that are always zero:

--- a/libstdc++-v3/src/c++11/shared_ptr.cc
+++ b/libstdc++-v3/src/c++11/shared_ptr.cc
@@ -41,7 +41,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     const unsigned char invalid = mask + 1;

     inline unsigned char key(const void* addr)
-    { return _Hash_impl::hash(addr) & mask; }
+    {
+      const int zero_bits = __builtin_ctz(alignof(shared_ptr<void>));
+      return _Hash_impl::hash(addzero_bitsaligned) & mask; }

     /* Returns different instances of __mutex depending on the passed address
      * in order to limit contention.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]