forked from OSchip/llvm-project
Put std::mutex usage behind #ifdefs to pacify the sanitizer buildbot
llvm-svn: 307925
This commit is contained in:
parent
e1088dc42b
commit
1c0f6ed45a
|
@ -45,22 +45,36 @@ static void *ErrorHandlerUserData = nullptr;
|
||||||
static fatal_error_handler_t BadAllocErrorHandler = nullptr;
|
static fatal_error_handler_t BadAllocErrorHandler = nullptr;
|
||||||
static void *BadAllocErrorHandlerUserData = nullptr;
|
static void *BadAllocErrorHandlerUserData = nullptr;
|
||||||
|
|
||||||
|
#if LLVM_ENABLE_THREADS == 1
|
||||||
// Mutexes to synchronize installing error handlers and calling error handlers.
|
// Mutexes to synchronize installing error handlers and calling error handlers.
|
||||||
// Do not use ManagedStatic, or that may allocate memory while attempting to
|
// Do not use ManagedStatic, or that may allocate memory while attempting to
|
||||||
// report an OOM.
|
// report an OOM.
|
||||||
|
//
|
||||||
|
// This usage of std::mutex has to be conditionalized behind ifdefs because
|
||||||
|
// of this script:
|
||||||
|
// compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh
|
||||||
|
// That script attempts to statically link the LLVM symbolizer library with the
|
||||||
|
// STL and hide all of its symbols with 'opt -internalize'. To reduce size, it
|
||||||
|
// cuts out the threading portions of the hermetic copy of libc++ that it
|
||||||
|
// builds. We can remove these ifdefs if that script goes away.
|
||||||
static std::mutex ErrorHandlerMutex;
|
static std::mutex ErrorHandlerMutex;
|
||||||
static std::mutex BadAllocErrorHandlerMutex;
|
static std::mutex BadAllocErrorHandlerMutex;
|
||||||
|
#endif
|
||||||
|
|
||||||
void llvm::install_fatal_error_handler(fatal_error_handler_t handler,
|
void llvm::install_fatal_error_handler(fatal_error_handler_t handler,
|
||||||
void *user_data) {
|
void *user_data) {
|
||||||
|
#if LLVM_ENABLE_THREADS == 1
|
||||||
std::lock_guard<std::mutex> Lock(ErrorHandlerMutex);
|
std::lock_guard<std::mutex> Lock(ErrorHandlerMutex);
|
||||||
|
#endif
|
||||||
assert(!ErrorHandler && "Error handler already registered!\n");
|
assert(!ErrorHandler && "Error handler already registered!\n");
|
||||||
ErrorHandler = handler;
|
ErrorHandler = handler;
|
||||||
ErrorHandlerUserData = user_data;
|
ErrorHandlerUserData = user_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void llvm::remove_fatal_error_handler() {
|
void llvm::remove_fatal_error_handler() {
|
||||||
|
#if LLVM_ENABLE_THREADS == 1
|
||||||
std::lock_guard<std::mutex> Lock(ErrorHandlerMutex);
|
std::lock_guard<std::mutex> Lock(ErrorHandlerMutex);
|
||||||
|
#endif
|
||||||
ErrorHandler = nullptr;
|
ErrorHandler = nullptr;
|
||||||
ErrorHandlerUserData = nullptr;
|
ErrorHandlerUserData = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +97,9 @@ void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) {
|
||||||
{
|
{
|
||||||
// Only acquire the mutex while reading the handler, so as not to invoke a
|
// Only acquire the mutex while reading the handler, so as not to invoke a
|
||||||
// user-supplied callback under a lock.
|
// user-supplied callback under a lock.
|
||||||
|
#if LLVM_ENABLE_THREADS == 1
|
||||||
std::lock_guard<std::mutex> Lock(ErrorHandlerMutex);
|
std::lock_guard<std::mutex> Lock(ErrorHandlerMutex);
|
||||||
|
#endif
|
||||||
handler = ErrorHandler;
|
handler = ErrorHandler;
|
||||||
handlerData = ErrorHandlerUserData;
|
handlerData = ErrorHandlerUserData;
|
||||||
}
|
}
|
||||||
|
@ -112,14 +128,18 @@ void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) {
|
||||||
|
|
||||||
void llvm::install_bad_alloc_error_handler(fatal_error_handler_t handler,
|
void llvm::install_bad_alloc_error_handler(fatal_error_handler_t handler,
|
||||||
void *user_data) {
|
void *user_data) {
|
||||||
|
#if LLVM_ENABLE_THREADS == 1
|
||||||
std::lock_guard<std::mutex> Lock(BadAllocErrorHandlerMutex);
|
std::lock_guard<std::mutex> Lock(BadAllocErrorHandlerMutex);
|
||||||
|
#endif
|
||||||
assert(!ErrorHandler && "Bad alloc error handler already registered!\n");
|
assert(!ErrorHandler && "Bad alloc error handler already registered!\n");
|
||||||
BadAllocErrorHandler = handler;
|
BadAllocErrorHandler = handler;
|
||||||
BadAllocErrorHandlerUserData = user_data;
|
BadAllocErrorHandlerUserData = user_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void llvm::remove_bad_alloc_error_handler() {
|
void llvm::remove_bad_alloc_error_handler() {
|
||||||
|
#if LLVM_ENABLE_THREADS == 1
|
||||||
std::lock_guard<std::mutex> Lock(BadAllocErrorHandlerMutex);
|
std::lock_guard<std::mutex> Lock(BadAllocErrorHandlerMutex);
|
||||||
|
#endif
|
||||||
BadAllocErrorHandler = nullptr;
|
BadAllocErrorHandler = nullptr;
|
||||||
BadAllocErrorHandlerUserData = nullptr;
|
BadAllocErrorHandlerUserData = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +150,9 @@ void llvm::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) {
|
||||||
{
|
{
|
||||||
// Only acquire the mutex while reading the handler, so as not to invoke a
|
// Only acquire the mutex while reading the handler, so as not to invoke a
|
||||||
// user-supplied callback under a lock.
|
// user-supplied callback under a lock.
|
||||||
|
#if LLVM_ENABLE_THREADS == 1
|
||||||
std::lock_guard<std::mutex> Lock(BadAllocErrorHandlerMutex);
|
std::lock_guard<std::mutex> Lock(BadAllocErrorHandlerMutex);
|
||||||
|
#endif
|
||||||
Handler = BadAllocErrorHandler;
|
Handler = BadAllocErrorHandler;
|
||||||
HandlerData = BadAllocErrorHandlerUserData;
|
HandlerData = BadAllocErrorHandlerUserData;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue