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

Side by Side Diff: rlz/lib/recursive_cross_process_lock_posix.cc

Issue 1096203003: rlz: Silence spam from lock RecursiveCrossProcessLock (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: oops.. add .value() Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "rlz/lib/recursive_cross_process_lock_posix.h" 5 #include "rlz/lib/recursive_cross_process_lock_posix.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/file.h> 9 #include <sys/file.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 25 matching lines...) Expand all
36 locking_thread_ = pthread_self(); 36 locking_thread_ = pthread_self();
37 37
38 // Try to acquire file lock. 38 // Try to acquire file lock.
39 if (just_got_lock) { 39 if (just_got_lock) {
40 const int kMaxTimeoutMS = 5000; // Matches Windows. 40 const int kMaxTimeoutMS = 5000; // Matches Windows.
41 const int kSleepPerTryMS = 200; 41 const int kSleepPerTryMS = 200;
42 42
43 CHECK(file_lock_ == -1); 43 CHECK(file_lock_ == -1);
44 file_lock_ = open(lock_filename.value().c_str(), O_RDWR | O_CREAT, 0666); 44 file_lock_ = open(lock_filename.value().c_str(), O_RDWR | O_CREAT, 0666);
45 if (file_lock_ == -1) { 45 if (file_lock_ == -1) {
46 perror("open"); 46 VPLOG(1) << "Failed to open: " << lock_filename.value();
47 return false; 47 return false;
48 } 48 }
49 49
50 int flock_result = -1; 50 int flock_result = -1;
51 int elapsed_ms = 0; 51 int elapsed_ms = 0;
52 while ((flock_result = 52 while ((flock_result =
53 HANDLE_EINTR(flock(file_lock_, LOCK_EX | LOCK_NB))) == -1 && 53 HANDLE_EINTR(flock(file_lock_, LOCK_EX | LOCK_NB))) == -1 &&
54 errno == EWOULDBLOCK && 54 errno == EWOULDBLOCK &&
55 elapsed_ms < kMaxTimeoutMS) { 55 elapsed_ms < kMaxTimeoutMS) {
56 usleep(kSleepPerTryMS * 1000); 56 usleep(kSleepPerTryMS * 1000);
57 elapsed_ms += kSleepPerTryMS; 57 elapsed_ms += kSleepPerTryMS;
58 } 58 }
59 59
60 if (flock_result == -1) { 60 if (flock_result == -1) {
61 perror("flock"); 61 VPLOG(1) << "Failed flock: " << lock_filename.value();
62 close(file_lock_); 62 close(file_lock_);
63 file_lock_ = -1; 63 file_lock_ = -1;
64 return false; 64 return false;
65 } 65 }
66 return true; 66 return true;
67 } else { 67 } else {
68 return file_lock_ != -1; 68 return file_lock_ != -1;
69 } 69 }
70 } 70 }
71 71
72 void RecursiveCrossProcessLock::ReleaseLock() { 72 void RecursiveCrossProcessLock::ReleaseLock() {
73 if (file_lock_ != -1) { 73 if (file_lock_ != -1) {
74 ignore_result(HANDLE_EINTR(flock(file_lock_, LOCK_UN))); 74 ignore_result(HANDLE_EINTR(flock(file_lock_, LOCK_UN)));
75 close(file_lock_); 75 close(file_lock_);
76 file_lock_ = -1; 76 file_lock_ = -1;
77 } 77 }
78 78
79 locking_thread_ = 0; 79 locking_thread_ = 0;
80 pthread_mutex_unlock(&recursive_lock_); 80 pthread_mutex_unlock(&recursive_lock_);
81 } 81 }
82 82
83 } // namespace rlz_lib 83 } // namespace rlz_lib
OLDNEW
« 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