summaryrefslogtreecommitdiff
path: root/src/compiler_llvm/compiler_llvm.cc
diff options
context:
space:
mode:
author Shih-wei Liao <sliao@google.com> 2012-04-20 15:27:44 -0700
committer Shih-wei Liao <sliao@google.com> 2012-04-20 16:47:54 -0700
commit766b0bfa92e820c40f5e7a27c828d5e7265b8db7 (patch)
treed008883974b71fe8b38e87fbf7dc4c26e0568114 /src/compiler_llvm/compiler_llvm.cc
parentd7726e4629f5e77d0bebdc1a5ffbb27ad7e91a1e (diff)
Remove the mutex lock from Materialize().
Change-Id: I98ebee1358e67085574cacbeb92744f86b1fac0f
Diffstat (limited to 'src/compiler_llvm/compiler_llvm.cc')
-rw-r--r--src/compiler_llvm/compiler_llvm.cc46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/compiler_llvm/compiler_llvm.cc b/src/compiler_llvm/compiler_llvm.cc
index 28320c74c6..2ebf5f65f7 100644
--- a/src/compiler_llvm/compiler_llvm.cc
+++ b/src/compiler_llvm/compiler_llvm.cc
@@ -137,44 +137,58 @@ void CompilerLLVM::EnsureCompilationUnit() {
void CompilerLLVM::MaterializeRemainder() {
- MutexLock GUARD(compiler_lock_);
- if (curr_cunit_ != NULL) {
- Materialize();
+ compiler_lock_.Lock();
+ // Localize
+ CompilationUnit* cunit = curr_cunit_;
+ // Reset the curr_cuit_
+ curr_cunit_ = NULL;
+ compiler_lock_.Unlock();
+
+ if (cunit != NULL) {
+ Materialize(cunit);
}
}
void CompilerLLVM::MaterializeIfThresholdReached() {
- MutexLock GUARD(compiler_lock_);
+ compiler_lock_.Lock();
+ // Localize
+ CompilationUnit* cunit = curr_cunit_;
+
if (curr_cunit_ != NULL && curr_cunit_->IsMaterializeThresholdReached()) {
- Materialize();
+ // Delete the compilation unit
+ curr_cunit_ = NULL;
+ } else {
+ // Reset cunit such that Materialize() won't be invoked
+ cunit = NULL;
}
-}
+ compiler_lock_.Unlock();
-void CompilerLLVM::Materialize() {
- compiler_lock_.AssertHeld();
+ if (cunit != NULL) {
+ Materialize(cunit);
+ }
+}
- DCHECK(curr_cunit_ != NULL);
- DCHECK(!curr_cunit_->IsMaterialized());
+
+void CompilerLLVM::Materialize(CompilationUnit* cunit) {
+ DCHECK(cunit != NULL);
+ DCHECK(!cunit->IsMaterialized());
// Write bitcode to file when filename is set
if (IsBitcodeFileNameAvailable()) {
const size_t cunit_idx = cunits_.size();
- curr_cunit_->WriteBitcodeToFile(
+ cunit->WriteBitcodeToFile(
StringPrintf("%s-%zu", bitcode_filename_.c_str(), cunit_idx));
}
// Materialize the llvm::Module into ELF object file
- curr_cunit_->Materialize();
+ cunit->Materialize();
// Load ELF image when automatic ELF loading is enabled
if (IsAutoElfLoadingEnabled()) {
- LoadElfFromCompilationUnit(curr_cunit_);
+ LoadElfFromCompilationUnit(cunit);
}
-
- // Delete the compilation unit
- curr_cunit_ = NULL;
}