mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-29 10:25:12 +00:00
Add llvm_start_multithreaded(), which starts up the LLVM internals in thread-safe mode. Provide double-check locking
initialization of ManagedStatic's when running in thread-safe mode. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72151 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -12,21 +12,44 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Support/ManagedStatic.h"
|
||||
#include "llvm/Config/config.h"
|
||||
#include "llvm/System/Atomic.h"
|
||||
#include "llvm/System/Mutex.h"
|
||||
#include <cassert>
|
||||
using namespace llvm;
|
||||
|
||||
static const ManagedStaticBase *StaticList = 0;
|
||||
|
||||
void ManagedStaticBase::RegisterManagedStatic(void *ObjPtr,
|
||||
static sys::Mutex* ManagedStaticMutex = 0;
|
||||
|
||||
void ManagedStaticBase::RegisterManagedStatic(void *(*Creator)(),
|
||||
void (*Deleter)(void*)) const {
|
||||
assert(Ptr == 0 && DeleterFn == 0 && Next == 0 &&
|
||||
"Partially init static?");
|
||||
Ptr = ObjPtr;
|
||||
DeleterFn = Deleter;
|
||||
if (ManagedStaticMutex) {
|
||||
ManagedStaticMutex->acquire();
|
||||
|
||||
if (Ptr == 0) {
|
||||
void* tmp = Creator ? Creator() : 0;
|
||||
|
||||
sys::MemoryFence();
|
||||
Ptr = tmp;
|
||||
DeleterFn = Deleter;
|
||||
|
||||
// Add to list of managed statics.
|
||||
Next = StaticList;
|
||||
StaticList = this;
|
||||
}
|
||||
|
||||
ManagedStaticMutex->release();
|
||||
} else {
|
||||
assert(Ptr == 0 && DeleterFn == 0 && Next == 0 &&
|
||||
"Partially initialized ManagedStatic!?");
|
||||
Ptr = Creator ? Creator() : 0;
|
||||
DeleterFn = Deleter;
|
||||
|
||||
// Add to list of managed statics.
|
||||
Next = StaticList;
|
||||
StaticList = this;
|
||||
// Add to list of managed statics.
|
||||
Next = StaticList;
|
||||
StaticList = this;
|
||||
}
|
||||
}
|
||||
|
||||
void ManagedStaticBase::destroy() const {
|
||||
@@ -45,9 +68,23 @@ void ManagedStaticBase::destroy() const {
|
||||
DeleterFn = 0;
|
||||
}
|
||||
|
||||
void llvm::llvm_start_multithreaded() {
|
||||
#if LLVM_MULTITHREADED
|
||||
assert(ManagedStaticMutex == 0 && "Multithreaded LLVM already initialized!");
|
||||
ManagedStaticMutex = new sys::Mutex(true);
|
||||
#else
|
||||
assert(0 && "LLVM built without multithreading support!");
|
||||
#endif
|
||||
}
|
||||
|
||||
/// llvm_shutdown - Deallocate and destroy all ManagedStatic variables.
|
||||
void llvm::llvm_shutdown() {
|
||||
while (StaticList)
|
||||
StaticList->destroy();
|
||||
|
||||
if (ManagedStaticMutex) {
|
||||
delete ManagedStaticMutex;
|
||||
ManagedStaticMutex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user