diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-07-28 00:45:10 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-07-28 00:45:10 +0000 |
commit | 08a2bfd230cfc8049b6015c7ca2a3cc7d2fadb2f (patch) | |
tree | 283e9aa2b4ae63f090f71cd664d7af9daa212b64 /clang/lib/Frontend/ASTUnit.cpp | |
parent | b7098a38b39758316d78c1a16f57227c5d2064ac (diff) | |
download | bcm5719-llvm-08a2bfd230cfc8049b6015c7ca2a3cc7d2fadb2f.tar.gz bcm5719-llvm-08a2bfd230cfc8049b6015c7ca2a3cc7d2fadb2f.zip |
Cut down the number of open/close system calls for output files.
For PCH files, have only one open/close for temporary + rename to be safe from race conditions.
For all other output files open/close the output file directly.
Depends on llvm r136310. rdar://9082880 & http://llvm.org/PR9374.
llvm-svn: 136315
Diffstat (limited to 'clang/lib/Frontend/ASTUnit.cpp')
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index c2901c18278..dea9ed139ab 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -2309,23 +2309,17 @@ CXSaveError ASTUnit::Save(StringRef File) { // Write to a temporary file and later rename it to the actual file, to avoid // possible race conditions. - llvm::sys::Path TempPath(File); - if (TempPath.makeUnique(/*reuse_current=*/false, /*ErrMsg*/0)) + llvm::SmallString<128> TempPath; + TempPath = File; + TempPath += "-%%%%%%%%"; + int fd; + if (llvm::sys::fs::unique_file(TempPath.str(), fd, TempPath, + /*makeAbsolute=*/false)) return CXSaveError_Unknown; - // makeUnique may or may not have created the file. Try deleting before - // opening so that we can use F_Excl for exclusive access. - TempPath.eraseFromDisk(); // FIXME: Can we somehow regenerate the stat cache here, or do we need to // unconditionally create a stat cache when we parse the file? - std::string ErrorInfo; - llvm::raw_fd_ostream Out(TempPath.c_str(), ErrorInfo, - llvm::raw_fd_ostream::F_Binary | - // if TempPath already exists, we should not try to - // overwrite it, we want to avoid race conditions. - llvm::raw_fd_ostream::F_Excl); - if (!ErrorInfo.empty() || Out.has_error()) - return CXSaveError_Unknown; + llvm::raw_fd_ostream Out(fd, /*shouldClose=*/true); serialize(Out); Out.close(); |