]> granicus.if.org Git - llvm/commitdiff
Use std::call_once on Windows
authorReid Kleckner <rnk@google.com>
Tue, 14 Feb 2017 01:21:39 +0000 (01:21 +0000)
committerReid Kleckner <rnk@google.com>
Tue, 14 Feb 2017 01:21:39 +0000 (01:21 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295013 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/Threading.h

index 44864a0ad0a8fa910d6231ec8e5692b0dc04d26c..20d21358f902254fd71546c81d7ede16887360d1 100644 (file)
 #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