diff --git a/common_clang.cpp b/common_clang.cpp index 79abbd79..426235ba 100644 --- a/common_clang.cpp +++ b/common_clang.cpp @@ -85,7 +85,7 @@ static volatile bool lazyCCInit = true; // the flag must be 'volatile' to prevent caching in a CPU register static llvm::sys::Mutex lazyCCInitMutex; -static llvm::ManagedStatic > compileMutex; +llvm::ManagedStatic> compileMutex; void CommonClangTerminate() { llvm::llvm_shutdown(); } @@ -212,6 +212,7 @@ Compile(const char *pszProgramSource, const char **pInputHeaders, CommonClangInitialize(); try { + llvm::sys::SmartScopedLock compileGuard{*compileMutex}; std::unique_ptr pResult(new OCLFEBinaryResult()); // Create the clang compiler @@ -223,8 +224,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders, // Prepare error log llvm::raw_string_ostream err_ostream(pResult->getLogRef()); { - llvm::sys::SmartScopedLock compileGuard {*compileMutex}; - // Parse options optionsParser.processOptions(pszOptions, pszOptionsEx); @@ -343,7 +342,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders, err_ostream.flush(); } { - llvm::sys::SmartScopedLock compileGuard {*compileMutex}; if (pBinaryResult) { *pBinaryResult = pResult.release(); } diff --git a/options_compile.cpp b/options_compile.cpp index 1c734ef9..db48db1c 100644 --- a/options_compile.cpp +++ b/options_compile.cpp @@ -39,7 +39,7 @@ Copyright (c) Intel Corporation (2009-2017). using namespace llvm::opt; -static llvm::ManagedStatic > compileOptionsMutex; +extern llvm::ManagedStatic> compileMutex; static const OptTable::Info ClangOptionsInfoTable[] = { #define PREFIX(NAME, VALUE) @@ -430,7 +430,7 @@ extern "C" CC_DLL_EXPORT bool CheckCompileOptions(const char *pszOptions, size_t uiUnknownOptionsSize) { // LLVM doesn't guarantee thread safety, // therefore we serialize execution of LLVM code. - llvm::sys::SmartScopedLock compileOptionsGuard {*compileOptionsMutex}; + llvm::sys::SmartScopedLock compileOptionsGuard{*compileMutex}; try { CompileOptionsParser optionsParser("200");