OSDN Git Service

Use std::mutex to avoid memory allocation after OOM
authorReid Kleckner <rnk@google.com>
Wed, 12 Jul 2017 18:23:06 +0000 (18:23 +0000)
committerReid Kleckner <rnk@google.com>
Wed, 12 Jul 2017 18:23:06 +0000 (18:23 +0000)
commit4157affe62efa138df3e3b5516aee2b358c5c146
tree05a82d4ebfa8a29335f80e198d9981e40f7fa36e
parenta4790a341b7088fb63242ea403c7fec0b22dd485
Use std::mutex to avoid memory allocation after OOM

ManagedStatic<sys::Mutex> would lazilly allocate a sys::Mutex to lock
when reporting an OOM, which is a bad idea.

The three STL implementations that I know of use pthread_mutex_lock and
EnterCriticalSection to implement std::mutex. I'm pretty sure that
neither of those allocate heap memory.

It seems that we unconditionally use std::mutex without testing
LLVM_ENABLE_THREADS elsewhere in the codebase, so this should be
portable.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307827 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Support/ErrorHandling.cpp