Fixing to allow multiple executions/process.

This commit is contained in:
Ben Vanik 2013-01-27 19:33:57 -08:00
parent 12d9c3d15e
commit 92a3e19cd9
1 changed files with 32 additions and 11 deletions

View File

@ -27,20 +27,42 @@ using namespace xe::cpu;
using namespace xe::kernel;
namespace {
void InitializeIfNeeded();
void CleanupOnShutdown();
void InitializeIfNeeded() {
static bool has_initialized = false;
if (has_initialized) {
return;
}
has_initialized = true;
// TODO(benvanik): only do this once
LLVMLinkInInterpreter();
LLVMLinkInJIT();
InitializeNativeTarget();
// TODO(benvanik): only do this once
codegen::RegisterEmitCategoryALU();
codegen::RegisterEmitCategoryControl();
codegen::RegisterEmitCategoryFPU();
codegen::RegisterEmitCategoryMemory();
atexit(CleanupOnShutdown);
}
void CleanupOnShutdown() {
llvm_shutdown();
}
}
Processor::Processor(xe_pal_ref pal, xe_memory_ref memory) {
pal_ = xe_pal_retain(pal);
memory_ = xe_memory_retain(memory);
// TODO(benvanik): only do this once
LLVMLinkInInterpreter();
LLVMLinkInJIT();
InitializeNativeTarget();
// TODO(benvanik): only do this once
codegen::RegisterEmitCategoryALU();
codegen::RegisterEmitCategoryControl();
codegen::RegisterEmitCategoryFPU();
codegen::RegisterEmitCategoryMemory();
InitializeIfNeeded();
}
Processor::~Processor() {
@ -51,7 +73,6 @@ Processor::~Processor() {
}
engine_.reset();
llvm_shutdown();
xe_memory_release(memory_);
xe_pal_release(pal_);