From: Reid Kleckner Date: Tue, 14 Feb 2017 01:21:39 +0000 (+0000) Subject: Use std::call_once on Windows X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6568ff645cc9575acd245e121e0a31683f786add;p=llvm 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295013 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/Threading.h b/include/llvm/Support/Threading.h index 44864a0ad0a..20d21358f90 100644 --- a/include/llvm/Support/Threading.h +++ b/include/llvm/Support/Threading.h @@ -20,11 +20,16 @@ #include // So we can check the C++ standard lib macros. #include +#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