diff options
author | Owen Anderson <resistor@mac.com> | 2009-06-17 22:53:57 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-06-17 22:53:57 +0000 |
commit | a23d2c126298b5193be46c7d4a1d079a9109ffaf (patch) | |
tree | 081a7c96cef91066a3f7630c6b6e9c583e9cf09f /lib/VMCore | |
parent | b983d67465a939c43173e381f9063d9d9245f45b (diff) | |
download | external_llvm-a23d2c126298b5193be46c7d4a1d079a9109ffaf.zip external_llvm-a23d2c126298b5193be46c7d4a1d079a9109ffaf.tar.gz external_llvm-a23d2c126298b5193be46c7d4a1d079a9109ffaf.tar.bz2 |
Use double-checked locking for this lazy initialization.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73653 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Type.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index b815eec..0add0af 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -453,8 +453,27 @@ void DerivedType::dropAllTypeUses() { if (NumContainedTys != 0) { // The type must stay abstract. To do this, we insert a pointer to a type // that will never get resolved, thus will always be abstract. - static Type *AlwaysOpaqueTy = OpaqueType::get(); - static PATypeHolder Holder(AlwaysOpaqueTy); + static Type *AlwaysOpaqueTy = 0; + static PATypeHolder* Holder = 0; + if (!AlwaysOpaqueTy) { + if (llvm_is_multithreaded()) { + llvm_acquire_global_lock(); + + if (!AlwaysOpaqueTy) { + Type *tmp = OpaqueType::get(); + PATypeHolder* tmp2 = new PATypeHolder(AlwaysOpaqueTy); + sys::MemoryFence(); + AlwaysOpaqueTy = tmp; + Holder = tmp2; + } + + llvm_release_global_lock(); + } else { + AlwaysOpaqueTy = OpaqueType::get(); + Holder = new PATypeHolder(AlwaysOpaqueTy); + } + } + ContainedTys[0] = AlwaysOpaqueTy; // Change the rest of the types to be Int32Ty's. It doesn't matter what we |