r211121 - Change libclang initialization to use std::call_once instead of

NAKAMURA Takumi geek4civic at gmail.com
Tue Jun 24 07:36:04 PDT 2014


Excuse me, I have reverted it in r211593. Support for <mutex> is
incomplete on cygming.

For Cygwin, clang is incapable of TLS, in despite of HAVE_TLS in
libstdc++'s c++config.h.
http://bb.pgr.jp/builders/clang-3stage-i686-cygwin/builds/458

For mingw32, please see the build log,
http://lab.llvm.org:8011/builders/clang-native-mingw32-win7

2014-06-18 4:57 GMT+09:00 Zachary Turner <zturner at google.com>:
> Author: zturner
> Date: Tue Jun 17 14:57:15 2014
> New Revision: 211121
>
> URL: http://llvm.org/viewvc/llvm-project?rev=211121&view=rev
> Log:
> Change libclang initialization to use std::call_once instead of
> hand rolled once-initialization, and rename the mutex to be more
> descriptive of its actual purpose.
>
> Modified:
>     cfe/trunk/tools/libclang/CIndex.cpp
>
> Modified: cfe/trunk/tools/libclang/CIndex.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=211121&r1=211120&r2=211121&view=diff
> ==============================================================================
> --- cfe/trunk/tools/libclang/CIndex.cpp (original)
> +++ cfe/trunk/tools/libclang/CIndex.cpp Tue Jun 17 14:57:15 2014
> @@ -51,6 +51,7 @@
>  #include "llvm/Support/Threading.h"
>  #include "llvm/Support/Timer.h"
>  #include "llvm/Support/raw_ostream.h"
> +#include <mutex>
>
>  #ifdef __APPLE__
>  #include <pthread.h>
> @@ -2559,8 +2560,8 @@ buildPieces(unsigned NameFlags, bool IsM
>  // Misc. API hooks.
>  //===----------------------------------------------------------------------===//
>
> -static llvm::sys::Mutex EnableMultithreadingMutex;
> -static bool EnabledMultithreading;
> +static llvm::sys::Mutex LoggingMutex;
> +static std::once_flag LibclangGlobalInitFlag;
>
>  static void fatal_error_handler(void *user_data, const std::string& reason,
>                                  bool gen_crash_diag) {
> @@ -2570,6 +2571,12 @@ static void fatal_error_handler(void *us
>    ::abort();
>  }
>
> +static void initializeLibClang() {
> +  // Install our error handler, and make sure multi-threading is enabled.
> +  llvm::llvm_start_multithreaded();
> +  llvm::install_fatal_error_handler(fatal_error_handler, nullptr);
> +}
> +
>  extern "C" {
>  CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
>                            int displayDiagnostics) {
> @@ -2578,15 +2585,7 @@ CXIndex clang_createIndex(int excludeDec
>    if (!getenv("LIBCLANG_DISABLE_CRASH_RECOVERY"))
>      llvm::CrashRecoveryContext::Enable();
>
> -  // Enable support for multithreading in LLVM.
> -  {
> -    llvm::sys::ScopedLock L(EnableMultithreadingMutex);
> -    if (!EnabledMultithreading) {
> -      llvm::install_fatal_error_handler(fatal_error_handler, nullptr);
> -      llvm::llvm_start_multithreaded();
> -      EnabledMultithreading = true;
> -    }
> -  }
> +  std::call_once(LibclangGlobalInitFlag, initializeLibClang);
>
>    CIndexer *CIdxr = new CIndexer();
>    if (excludeDeclarationsFromPCH)
> @@ -6962,7 +6961,7 @@ Logger &cxindex::Logger::operator<<(cons
>  cxindex::Logger::~Logger() {
>    LogOS.flush();
>
> -  llvm::sys::ScopedLock L(EnableMultithreadingMutex);
> +  llvm::sys::ScopedLock L(LoggingMutex);
>
>    static llvm::TimeRecord sBeginTR = llvm::TimeRecord::getCurrentTime();
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list