diff options
Diffstat (limited to 'runtime/class_linker.cc')
| -rw-r--r-- | runtime/class_linker.cc | 57 |
1 files changed, 2 insertions, 55 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index a43fda1135..7385382359 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -27,6 +27,7 @@ #include "base/casts.h" #include "base/logging.h" +#include "base/scoped_flock.h" #include "base/stl_util.h" #include "base/unix_file/fd_file.h" #include "class_linker-inl.h" @@ -701,60 +702,6 @@ const DexFile* ClassLinker::FindDexFileInOatLocation(const char* dex_location, return dex_file; } -class ScopedFlock { - public: - ScopedFlock() {} - - bool Init(const char* filename, std::string* error_msg) { - while (true) { - file_.reset(OS::OpenFileWithFlags(filename, O_CREAT | O_RDWR)); - if (file_.get() == NULL) { - *error_msg = StringPrintf("Failed to open file '%s': %s", filename, strerror(errno)); - return false; - } - int flock_result = TEMP_FAILURE_RETRY(flock(file_->Fd(), LOCK_EX)); - if (flock_result != 0) { - *error_msg = StringPrintf("Failed to lock file '%s': %s", filename, strerror(errno)); - return false; - } - struct stat fstat_stat; - int fstat_result = TEMP_FAILURE_RETRY(fstat(file_->Fd(), &fstat_stat)); - if (fstat_result != 0) { - *error_msg = StringPrintf("Failed to fstat file '%s': %s", filename, strerror(errno)); - return false; - } - struct stat stat_stat; - int stat_result = TEMP_FAILURE_RETRY(stat(filename, &stat_stat)); - if (stat_result != 0) { - PLOG(WARNING) << "Failed to stat, will retry: " << filename; - // ENOENT can happen if someone racing with us unlinks the file we created so just retry. - continue; - } - if (fstat_stat.st_dev != stat_stat.st_dev || fstat_stat.st_ino != stat_stat.st_ino) { - LOG(WARNING) << "File changed while locking, will retry: " << filename; - continue; - } - return true; - } - } - - File& GetFile() { - return *file_; - } - - ~ScopedFlock() { - if (file_.get() != NULL) { - int flock_result = TEMP_FAILURE_RETRY(flock(file_->Fd(), LOCK_UN)); - CHECK_EQ(0, flock_result); - } - } - - private: - std::unique_ptr<File> file_; - - DISALLOW_COPY_AND_ASSIGN(ScopedFlock); -}; - const DexFile* ClassLinker::FindOrCreateOatFileForDexLocation( const char* dex_location, uint32_t dex_location_checksum, @@ -785,7 +732,7 @@ const DexFile* ClassLinker::FindOrCreateOatFileForDexLocation( // Generate the output oat file for the dex file VLOG(class_linker) << "Generating oat file " << oat_location << " for " << dex_location; - if (!GenerateOatFile(dex_location, scoped_flock.GetFile().Fd(), oat_location, &error_msg)) { + if (!GenerateOatFile(dex_location, scoped_flock.GetFile()->Fd(), oat_location, &error_msg)) { CHECK(!error_msg.empty()); error_msgs->push_back(error_msg); return nullptr; |