Chromium Code Reviews| Index: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
| diff --git a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
| index 98b4c9453d376aa24450476a1991068f6e7e1443..38714cdaddb9ebd915762120fb237ae28303415a 100644 |
| --- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
| +++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
| @@ -20,6 +20,13 @@ |
| #include <unordered_map> |
| #include <unordered_set> |
| +#if defined(_WIN32) |
| +#include <windows.h> |
| +#else |
| +#include <sys/file.h> |
| +#include <unistd.h> |
| +#endif |
| + |
| #include "clang/AST/ASTContext.h" |
| #include "clang/ASTMatchers/ASTMatchFinder.h" |
| #include "clang/ASTMatchers/ASTMatchers.h" |
| @@ -511,6 +518,17 @@ int main(int argc, const char* argv[]) { |
| if (result != 0) |
| return result; |
| +#if defined(_WIN32) |
| + HFILE lockfd = CreateFile("rewrite-sym.lock", GENERIC_READ, FILE_SHARE_READ, |
| + NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
| + OVERLAPPED lock_out = {}; |
| + LockFileEx(lockfd, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &lock_out); |
| +#else |
| + int lockfd = open("rewrite-sym.lock", O_RDWR | O_CREAT, 0666); |
| + while (flock(lockfd, LOCK_EX)) { // :D |
| + } |
| +#endif |
| + |
| std::ofstream replacement_db_file("rewrite-sym.txt", |
| std::ios_base::out | std::ios_base::app); |
| for (const auto& p : field_decl_rewriter.replacement_names()) |
| @@ -523,6 +541,15 @@ int main(int argc, const char* argv[]) { |
| replacement_db_file << "fun:" << p.first << ":" << p.second << "\n"; |
| replacement_db_file.close(); |
| +#if defined(_WIN32) |
| + OVERLAPPED unlock_out = {}; |
| + UnlockFileEx(lockfd, 0, 1, 0, &unlock_out); |
|
dcheng
2016/01/26 23:41:45
I think (?) you should pass in the OVERLAPPED stru
danakj
2016/01/26 23:43:51
I was worried that it is an inout so I would have
danakj
2016/01/26 23:44:52
Done.
|
| + CloseHandle(lockfd); |
| +#else |
| + flock(lockfd, LOCK_UN); |
| + close(lockfd); |
| +#endif |
| + |
| // Serialization format is documented in tools/clang/scripts/run_tool.py |
| llvm::outs() << "==== BEGIN EDITS ====\n"; |
| for (const auto& r : replacements) { |