[llvm-commits] [llvm] r73653 - /llvm/trunk/lib/VMCore/Type.cpp
Owen Anderson
resistor at mac.com
Wed Jun 17 15:53:57 PDT 2009
Author: resistor
Date: Wed Jun 17 17:53:57 2009
New Revision: 73653
URL: http://llvm.org/viewvc/llvm-project?rev=73653&view=rev
Log:
Use double-checked locking for this lazy initialization.
Modified:
llvm/trunk/lib/VMCore/Type.cpp
Modified: llvm/trunk/lib/VMCore/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=73653&r1=73652&r2=73653&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Type.cpp (original)
+++ llvm/trunk/lib/VMCore/Type.cpp Wed Jun 17 17:53:57 2009
@@ -453,8 +453,27 @@
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
More information about the llvm-commits
mailing list