<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">I think it’s fine to give such a class the same interface as std::mutex, just please don’t actually name it std::mutex.  I would be pretty concerned about ABI compatibility in that situation, as well as subtle interactions with things like
 condition_variable::wait.  cxxabi::__mutex, or almost any other identifier would be fine.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> libcxx-dev <libcxx-dev-bounces@lists.llvm.org> <b>
On Behalf Of </b>Olivier Giroux via libcxx-dev<br>
<b>Sent:</b> Friday, May 17, 2019 7:55 PM<br>
<b>To:</b> JF Bastien <jfbastien@apple.com>; Mitch Phillips <mitchphillips@outlook.com><br>
<b>Cc:</b> kostyak@google.com; libcxx-dev@lists.llvm.org<br>
<b>Subject:</b> [EXTERNAL] Re: [libcxx-dev] Is a compiler-rt shared spinlock implementation of any use to libcxx?<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">That’s what makes the most sense to me, include <mutex> with a macro that freestanding would also use. Inside of that, I would have an implementation of standard mutex backed by atomics and the atomic_wait/atomic_notify_* functions, themselves
 configured with a macro to not rely on the OS in freestanding implementations.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Olivier<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black">libcxx-dev <<a href="mailto:libcxx-dev-bounces@lists.llvm.org">libcxx-dev-bounces@lists.llvm.org</a>> on behalf of JF Bastien via
 libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org">libcxx-dev@lists.llvm.org</a>><br>
<b>Reply-To: </b>JF Bastien <<a href="mailto:jfbastien@apple.com">jfbastien@apple.com</a>><br>
<b>Date: </b>Friday, May 17, 2019 at 4:40 PM<br>
<b>To: </b>Mitch Phillips <<a href="mailto:mitchphillips@outlook.com">mitchphillips@outlook.com</a>><br>
<b>Cc: </b>"<a href="mailto:kostyak@google.com">kostyak@google.com</a>" <<a href="mailto:kostyak@google.com">kostyak@google.com</a>>, "<a href="mailto:libcxx-dev@lists.llvm.org">libcxx-dev@lists.llvm.org</a>" <<a href="mailto:libcxx-dev@lists.llvm.org">libcxx-dev@lists.llvm.org</a>><br>
<b>Subject: </b>Re: [libcxx-dev] Is a compiler-rt shared spinlock implementation of any use to libcxx?<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">I think it makes sense for libc++ to have a version of mutex which has the same API as the standard one, but for “freestanding” platforms such as yours. A flavor which mostly just spins and yields as in your review.
<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I’m not sure how to best turn it on, though. Should it be controlled by a macro, and otherwise it just looks like you’re using <mutex>?<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On May 17, 2019, at 1:49 PM, Mitch Phillips via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org">libcxx-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">Hi all, <o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">In a recent <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D61923-231503272&d=DwMGaQ&c=I_0YwoKy7z5LMTVdyO6YCiE2uzI1jjZZuIPelcSjixA&r=y8mub81SfUi-UCZRX0Vl1g&m=yw9dJtPZSvMNi00nrRSUlnN4NTQzKvXzHbd5w8ShH8A&s=uW10gtroz30NxGIUU3BvNH5efGnzv2tds3P49eY5ri4&e=">
discussion</a> from the reviews of <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D60593&d=DwMGaQ&c=I_0YwoKy7z5LMTVdyO6YCiE2uzI1jjZZuIPelcSjixA&r=y8mub81SfUi-UCZRX0Vl1g&m=yw9dJtPZSvMNi00nrRSUlnN4NTQzKvXzHbd5w8ShH8A&s=rKVj5vHVGEsEZRjMkiN2X6e0bAfdTY7iVW0laX2AO8o&e=">
GWP-ASan</a>, it was mentioned that I should probably consult with cxx-dev to see whether they'd be interested in a common spinlock implementation.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The problem is:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> - Scudo hardened allocator (compiler-rt/lib/scudo) requires its own spinlock as it can't use the C++ standard library due to Fuchsia requirements.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> - GWP-ASan (as it's packaged into Scudo) also requires a spinlock.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> - Compiler-rt sanitizer_common also can't use c++ stdlib, and has its own spinlock. We can't reuse the sanitizer_common spinlock for Scudo/GWP-ASan as it's currently tightly coupled into sanitizer_common, and Scudo+Fuchsia can't afford
 the code size overhead of pulling the entire sanitizer_common library.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The plan was to basically write a small standalone spinlock implementation that can be used by all three of these requirements. Would libcxx benefit by us making this an llvm-common spinlock rather than compiler-rt-common? If so, are there
 any requirements that we need to be aware of?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Cheers,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Mitch.<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">_______________________________________________<br>
libcxx-dev mailing list<br>
<a href="mailto:libcxx-dev@lists.llvm.org">libcxx-dev@lists.llvm.org</a><br>
<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_libcxx-2Ddev&d=DwQGaQ&c=I_0YwoKy7z5LMTVdyO6YCiE2uzI1jjZZuIPelcSjixA&r=y8mub81SfUi-UCZRX0Vl1g&m=yw9dJtPZSvMNi00nrRSUlnN4NTQzKvXzHbd5w8ShH8A&s=SLhw06SYT_9fwfHOjm_nzQZ0LuPvmMe_b2gjd-VEFcc&e=">https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev</a><o:p></o:p></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="100%" align="center">
</div>
</div>
<div>
<p class="MsoNormal">This email message is for the sole use of the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact
 the sender by reply email and destroy all copies of the original message. <o:p></o:p></p>
</div>
<div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="100%" align="center">
</div>
</div>
</div>
</div>
</body>
</html>