<div dir="ltr">Hi Ben,<div><br></div><div>Looks like there's a typo in this patch that is causing a buildbot failure: <a href="http://lab.llvm.org:8011/builders/libcxx-libcxxabi-singlethreaded-x86_64-linux-debian/builds/1128/steps/build.libcxx/logs/stdio">http://lab.llvm.org:8011/builders/libcxx-libcxxabi-singlethreaded-x86_64-linux-debian/builds/1128/steps/build.libcxx/logs/stdio</a></div><div><br></div><div>Also seen in our local builders. I will fix it if I get around to it before you :)</div><div><br></div><div>Cheers,</div><div><br></div><div>/ Asiri</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 1, 2016 at 6:51 PM, Ben Craig via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: bcraig<br>
Date: Mon Aug  1 12:51:26 2016<br>
New Revision: 277357<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=277357&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=277357&view=rev</a><br>
Log:<br>
Improve shared_ptr dtor performance<br>
<br>
If the last destruction is uncontended, skip the atomic store on<br>
__shared_weak_owners_. This shifts some costs from normal<br>
shared_ptr usage to weak_ptr uses.<br>
<br>
<a href="https://reviews.llvm.org/D22470" rel="noreferrer" target="_blank">https://reviews.llvm.org/D22470</a><br>
<br>
Modified:<br>
    libcxx/trunk/src/memory.cpp<br>
<br>
Modified: libcxx/trunk/src/memory.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/memory.cpp?rev=277357&r1=277356&r2=277357&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/memory.cpp?rev=277357&r1=277356&r2=277357&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/src/memory.cpp (original)<br>
+++ libcxx/trunk/src/memory.cpp Mon Aug  1 12:51:26 2016<br>
@@ -96,7 +96,35 @@ __shared_weak_count::__release_shared()<br>
 void<br>
 __shared_weak_count::__release_weak() _NOEXCEPT<br>
 {<br>
-    if (decrement(__shared_weak_owners_) == -1)<br>
+    // NOTE: The acquire load here is an optimization of the very<br>
+    // common case where a shared pointer is being destructed while<br>
+    // having no other contended references.<br>
+    //<br>
+    // BENEFIT: We avoid expensive atomic stores like XADD and STREX<br>
+    // in a common case.  Those instructions are slow and do nasty<br>
+    // things to caches.<br>
+    //<br>
+    // IS THIS SAFE?  Yes.  During weak destruction, if we see that we<br>
+    // are the last reference, we know that no-one else is accessing<br>
+    // us. If someone were accessing us, then they would be doing so<br>
+    // while the last shared / weak_ptr was being destructed, and<br>
+    // that's undefined anyway.<br>
+    //<br>
+    // If we see anything other than a 0, then we have possible<br>
+    // contention, and need to use an atomicrmw primitive.<br>
+    // The same arguments don't apply for increment, where it is legal<br>
+    // (though inadvisable) to share shared_ptr references between<br>
+    // threads, and have them all get copied at once.  The argument<br>
+    // also doesn't apply for __release_shared, because an outstanding<br>
+    // weak_ptr::lock() could read / modify the shared count.<br>
+    if (__libcpp_atomic_load(&__shared_weak_owners_, _AO_Aquire) == 0)<br>
+    {<br>
+        // no need to do this store, because we are about<br>
+        // to destroy everything.<br>
+        //__libcpp_atomic_store(&__shared_weak_owners_, -1, _AO_Release);<br>
+        __on_zero_shared_weak();<br>
+    }<br>
+    else if (decrement(__shared_weak_owners_) == -1)<br>
         __on_zero_shared_weak();<br>
 }<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>