summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-06-17 22:53:57 +0000
committerOwen Anderson <resistor@mac.com>2009-06-17 22:53:57 +0000
commit89ee957cbd02ed08778b543c015fa59efe0c8b0f (patch)
treed42f793ecb92f4ea9f0b9a0d6fdd7948bc25aab6
parent3df1978270c98b653879fcad35b6848f565e820c (diff)
downloadbcm5719-llvm-89ee957cbd02ed08778b543c015fa59efe0c8b0f.tar.gz
bcm5719-llvm-89ee957cbd02ed08778b543c015fa59efe0c8b0f.zip
Use double-checked locking for this lazy initialization.
llvm-svn: 73653
-rw-r--r--llvm/lib/VMCore/Type.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/llvm/lib/VMCore/Type.cpp b/llvm/lib/VMCore/Type.cpp
index b815eec665b..0add0af3b84 100644
--- a/llvm/lib/VMCore/Type.cpp
+++ b/llvm/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
OpenPOWER on IntegriCloud