[llvm-commits] [llvm] r73636 - /llvm/trunk/lib/VMCore/Pass.cpp
Owen Anderson
resistor at mac.com
Wed Jun 17 14:16:28 PDT 2009
Author: resistor
Date: Wed Jun 17 16:16:20 2009
New Revision: 73636
URL: http://llvm.org/viewvc/llvm-project?rev=73636&view=rev
Log:
We need to use double-checked locking for lazy initialization in this case when running multithreaded.
Modified:
llvm/trunk/lib/VMCore/Pass.cpp
Modified: llvm/trunk/lib/VMCore/Pass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Pass.cpp?rev=73636&r1=73635&r2=73636&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Pass.cpp (original)
+++ llvm/trunk/lib/VMCore/Pass.cpp Wed Jun 17 16:16:20 2009
@@ -19,6 +19,8 @@
#include "llvm/ModuleProvider.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/Threading.h"
+#include "llvm/System/Atomic.h"
#include <algorithm>
#include <map>
#include <set>
@@ -192,8 +194,20 @@
// ressurection after llvm_shutdown is run.
static PassRegistrar *getPassRegistrar() {
static PassRegistrar *PassRegistrarObj = 0;
+
+ // Use double-checked locking to safely initialize the registrar when
+ // we're running in multithreaded mode.
if (!PassRegistrarObj)
- PassRegistrarObj = new PassRegistrar();
+ if (llvm_is_multithreaded()) {
+ llvm_acquire_global_lock();
+ if (!PassRegistrarObj) {
+ PassRegistrar* tmp = new PassRegistrar();
+ sys::MemoryFence();
+ PassRegistrarObj = tmp;
+ }
+ llvm_release_global_lock();
+ } else
+ PassRegistrarObj = new PassRegistrar();
return PassRegistrarObj;
}
More information about the llvm-commits
mailing list