summaryrefslogtreecommitdiff
path: root/dex2oat/dex2oat.cc
diff options
context:
space:
mode:
Diffstat (limited to 'dex2oat/dex2oat.cc')
-rw-r--r--dex2oat/dex2oat.cc27
1 files changed, 12 insertions, 15 deletions
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index b88fe09359..2e8d1930f1 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -2153,30 +2153,27 @@ class Dex2Oat FINAL {
// cleaning up before that (e.g. the oat writers are created before the
// runtime).
profile_compilation_info_.reset(new ProfileCompilationInfo());
- ScopedFlock flock;
- bool success = true;
+ ScopedFlock profile_file;
std::string error;
if (profile_file_fd_ != -1) {
- // The file doesn't need to be flushed so don't check the usage.
- // Pass a bogus path so that we can easily attribute any reported error.
- File file(profile_file_fd_, "profile", /*check_usage*/ false, /*read_only_mode*/ true);
- if (flock.Init(&file, &error)) {
- success = profile_compilation_info_->Load(profile_file_fd_);
- }
+ profile_file = LockedFile::DupOf(profile_file_fd_, "profile",
+ true /* read_only_mode */, &error);
} else if (profile_file_ != "") {
- if (flock.Init(profile_file_.c_str(), O_RDONLY, /* block */ true, &error)) {
- success = profile_compilation_info_->Load(flock.GetFile()->Fd());
- }
+ profile_file = LockedFile::Open(profile_file_.c_str(), O_RDONLY, true, &error);
}
- if (!error.empty()) {
- LOG(WARNING) << "Cannot lock profiles: " << error;
+
+ // Return early if we're unable to obtain a lock on the profile.
+ if (profile_file.get() == nullptr) {
+ LOG(ERROR) << "Cannot lock profiles: " << error;
+ return false;
}
- if (!success) {
+ if (!profile_compilation_info_->Load(profile_file->Fd())) {
profile_compilation_info_.reset(nullptr);
+ return false;
}
- return success;
+ return true;
}
private: