<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Dec 30, 2018, at 21:17, Olivier Giroux via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org" class="">libcxx-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">In my last mail, and in some F2F discussions, I volunteered to write a first patch to use a Freestanding configuration. My motivation is to decouple non-lock-free atomic<T> from platform libraries, from libatomic.a, for Freestanding implementations.<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">I’ve gone ahead and prototyped this a few different ways. Here is the approach I would like to submit a patch for.<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">= Background =<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">To the best of my ability to tell:<o:p class=""></o:p></span></div><ol start="1" type="a" style="margin-bottom: 0in; margin-top: 0in;" class=""><li class="MsoListParagraph" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;"><span style="font-size: 11pt;" class="">The libcxx implementation of atomic<T> is layered on __c11_atomic_* builtins, in all cases.<o:p class=""></o:p></span></li><li class="MsoListParagraph" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;"><span style="font-size: 11pt;" class="">If they’re missing, but __atomic_* builtins are there, then a fake __c11_atomic_* API is layered onto __atomic_*.<o:p class=""></o:p></span><ol start="1" type="a" style="margin-bottom: 0in; margin-top: 0in;" class=""><li class="MsoListParagraph" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;"><span style="font-size: 11pt;" class="">If neither are there, the configuration is unsupported.<o:p class=""></o:p></span></li></ol></li><li class="MsoListParagraph" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;"><span style="font-size: 11pt;" class="">If something is needed that’s not in C11, then it uses __atomic_* for that, even when it uses __c11_atomic_* for the rest.<o:p class=""></o:p></span><ol start="1" type="a" style="margin-bottom: 0in; margin-top: 0in;" class=""><li class="MsoListParagraph" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;"><span style="font-size: 11pt;" class="">e.g. __atomic_always_lock_free, in C++17 mode.<o:p class=""></o:p></span></li></ol></li></ol><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">This is working fine, but it makes it hard to customize behaviors like “<i class="">send non-lock-free atomics to another backend</i>” because in the case when __c11_atomic_* builtins are there, they are used directly without any adaptation. This makes it so you can only customize in the atomic<T> object specializations, which are set in your ABI and .<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">= Proposed Changes =<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">This approach is the best of three I tried on trunk libcxx:<o:p class=""></o:p></span></div><ol start="1" type="1" style="margin-bottom: 0in; margin-top: 0in;" class=""><li class="MsoListParagraph" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;"><span style="font-size: 11pt;" class="">Create a single __cxx_atomic_* layer which is an adaptation of either __c11_atomic_*, preferentially, or else __atomic_*. (For __atomic_*, it’s a rename of the layer that’s there now. For __c11_atomic_*, it’s a new but boring wrapper that just forwards calls.)<o:p class=""></o:p></span></li><li class="MsoListParagraph" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;"><span style="font-size: 11pt;" class="">Create a __cxx_atomic_type<> template that is an alias to what should wrap the _Tp inside of an atomic<T> / atomic_flag. Defaults to the same _Atomic(_Tp) as today, either from C11 or from the adaptation layer.<o:p class=""></o:p></span></li><li class="MsoListParagraph" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;"><span style="font-size: 11pt;" class="">Under #ifdef LIBCXX_FREESTANDING, introduce __cxx_locked_atomic_type<> with an implementation of __cxx_atomic_*, and redirect __cxx_atomic_type<> based on always-lock-freedom.<o:p class=""></o:p></span><ol start="1" type="a" style="margin-bottom: 0in; margin-top: 0in;" class=""><li class="MsoListParagraph" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;"><span style="font-size: 11pt;" class="">In C++17 mode, it uses __atomic_is_always_lock_free.<o:p class=""></o:p></span></li><li class="MsoListParagraph" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;"><span style="font-size: 11pt;" class="">Otherwise, it uses the C lock-free macros as shown in<span class="Apple-converted-space"> </span><a href="http://wg21.link/p0152" style="color: rgb(149, 79, 114); text-decoration: underline;" class="">wg21.link/p0152</a>.<o:p class=""></o:p></span></li></ol></li><li class="MsoListParagraph" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;"><span style="font-size: 11pt;" class="">Add a test that instantiates every specialization flavor of atomic<T>, as well as at least one “large” type that ought not be lock-free. It’s kind of weird that this isn’t in the test suite.<o:p class=""></o:p></span></li></ol><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">= Disclaimer =<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">I don’t have a strong grasp of what’s an ABI break here, my proposal reflects my limited mental model.<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">Some of the code parsed in Hosted builds does change, but none of the atomic<T> object sizes/alignments and member function signatures change in that configuration. In the Freestanding configuration, the non-lock-free atomic<T> change in size. My limited sense says this is OK – first that Hosted is going to be OK, and that it’s OK for Freestanding to differ here.<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">= Next Steps =<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">I’ll take all your feedback and questions, or I can make a patch and discuss it over code. But I think you mean to poke at motivation/design first.<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">I know it’s New Year’s Eve-ish and you’re all away, I’ll be patient.<o:p class=""></o:p></span></div></div></div></blockquote><br class=""></div><div>I just saw this, hence the late reply. At a high level, I'm fine with the proposed approach but I'd like to discuss it over a review to get things more concrete. Note that I'll only be back on Jan 21 though so don't expect a lot of feedback from me until then.</div><div><br class=""></div><div>Louis</div><div><br class=""></div></body></html>