Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp

Issue 1616223002: rewrite_to_chrome_style: Add a lock file when writing replacements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rewrite-operators
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b56c03fd9654d45e48618cd0821e18700d9115e4 100644
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
@@ -13,6 +13,7 @@
// void doThisThenThat() => void DoThisAndThat()
#include <assert.h>
+#include <string.h>
#include <algorithm>
#include <fstream>
#include <memory>
@@ -20,6 +21,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 +519,18 @@ int main(int argc, const char* argv[]) {
if (result != 0)
return result;
+#if defined(_WIN32)
+ OFSTRUCT lockfd_out;
+ HFILE lockfd = OpenFile("rewrite-sym.lock", &lockfd_out, OF_CREATE);
+ OVERLAPPED lock_out;
+ memset(&lock_out, 0, sizeof(lock_out));
dcheng 2016/01/22 00:31:30 OVERLAPPED lock_out = {}; then you can skip the m
danakj 2016/01/22 23:33:36 Fancy~
+ 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
dcheng 2016/01/22 00:31:30 Do we need to worry about contention here? Is ther
danakj 2016/01/22 23:33:36 I think it's okay, it takes like ~20min to run the
+ }
+#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 +543,14 @@ int main(int argc, const char* argv[]) {
replacement_db_file << "fun:" << p.first << ":" << p.second << "\n";
replacement_db_file.close();
+#if defined(_WIN32)
+ UnlockFile(lockfd, 0, 0, 1, 0);
+ 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) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698