[libcxx-commits] [libcxx] [libc++] Speed up classic locale (PR #72112)
Dmitry Vyukov via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Nov 16 06:03:35 PST 2023
================
@@ -538,16 +543,31 @@ locale::__imp::use_facet(long id) const
// locale
+std::atomic<locale::__imp*> locale::__imp::classic_;
+
const locale&
locale::__imp::make_classic()
{
// only one thread can get in here and it only gets in once
alignas(locale) static std::byte buf[sizeof(locale)];
locale* c = reinterpret_cast<locale*>(&buf);
c->__locale_ = &make<__imp>(1u);
+ classic_.store(c->__locale_, std::memory_order_relaxed);
----------------
dvyukov wrote:
Added a comment explaining why relaxed ordering is the right one.
https://github.com/llvm/llvm-project/pull/72112
More information about the libcxx-commits
mailing list