mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-04 01:11:44 +00:00
We need to use double-checked locking for lazy initialization in this case when running multithreaded.
llvm-svn: 73636
This commit is contained in:
parent
bbf53428f9
commit
a4471607bc
@ -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 @@ static std::vector<PassRegistrationListener*> *Listeners = 0;
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user