[llvm] r295013 - Use std::call_once on Windows

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 13 17:21:39 PST 2017


Author: rnk
Date: Mon Feb 13 19:21:39 2017
New Revision: 295013

URL: http://llvm.org/viewvc/llvm-project?rev=295013&view=rev
Log:
Use std::call_once on Windows

Previously we could not use it because std::once_flag's default
constructor was not constexpr. Today, all supported versions of VS
correctly mark it constexpr. I confirmed that MSVC 2015 does not emit
any problematic racy dynamic initialization code, so we should be safe
to use this now.

Modified:
    llvm/trunk/include/llvm/Support/Threading.h

Modified: llvm/trunk/include/llvm/Support/Threading.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Threading.h?rev=295013&r1=295012&r2=295013&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Threading.h (original)
+++ llvm/trunk/include/llvm/Support/Threading.h Mon Feb 13 19:21:39 2017
@@ -20,11 +20,16 @@
 #include <ciso646> // So we can check the C++ standard lib macros.
 #include <functional>
 
+#if defined(_MSC_VER)
+// MSVC's call_once implementation worked since VS 2015, which is the minimum
+// supported version as of this writing.
+#define LLVM_THREADING_USE_STD_CALL_ONCE 1
+#elif defined(LLVM_ON_UNIX) &&                                                 \
+    (defined(_LIBCPP_VERSION) ||                                               \
+     !(defined(__NetBSD__) || defined(__OpenBSD__) || defined(__ppc__)))
 // std::call_once from libc++ is used on all Unix platforms. Other
 // implementations like libstdc++ are known to have problems on NetBSD,
 // OpenBSD and PowerPC.
-#if defined(LLVM_ON_UNIX) && (defined(_LIBCPP_VERSION) ||                      \
-    !(defined(__NetBSD__) || defined(__OpenBSD__) || defined(__ppc__)))
 #define LLVM_THREADING_USE_STD_CALL_ONCE 1
 #else
 #define LLVM_THREADING_USE_STD_CALL_ONCE 0




More information about the llvm-commits mailing list