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

Unified Diff: chrome/common/multi_process_lock_win.cc

Issue 4721001: Add multi_process_lock to chrome/common (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: forced the over unlock case Created 10 years, 1 month 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
Index: chrome/common/multi_process_lock_win.cc
diff --git a/chrome/common/multi_process_lock_win.cc b/chrome/common/multi_process_lock_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b765c7ba1b7dce43448a83995b0ac31effcf3993
--- /dev/null
+++ b/chrome/common/multi_process_lock_win.cc
@@ -0,0 +1,61 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/multi_process_lock.h"
+
+#include "base/logging.h"
+#include "base/utf_string_conversions.h"
+#include "base/win/scoped_handle.h"
+
+class MultiProcessLockWin : public MultiProcessLock {
+ public:
+ explicit MultiProcessLockWin(const std::string& name)
+ : name_(name), count_(0) { }
+
+ virtual ~MultiProcessLockWin() {
+ if (count_ > 0) {
+ Unlock();
+ }
+ }
+
+ virtual bool TryLock() {
+ if (count_ > 0) {
+ count_ += 1;
+ return true;
+ }
+ string16 wname = UTF8ToUTF16(name_);
+ HANDLE event = CreateEvent(NULL, FALSE, FALSE, wname.c_str());
+ if (event && GetLastError() != ERROR_ALREADY_EXISTS) {
+ event_.Set(event);
+ count_ = 1;
+ return true;
+ } else {
+ if (event) {
+ CloseHandle(event);
+ }
+ return false;
+ }
+ }
+
+ virtual void Unlock() {
+ if (count_ == 0) {
+ DLOG(ERROR) << "Over unlocked MultiProcessLock " << name_;
Mark Mentovai 2010/11/11 23:45:24 hypheny (and the Linux file too.)
dmac 2010/11/12 00:36:26 Done.
+ return;
+ }
+ count_ -= 1;
+ if (count_ == 0) {
+ event_.Set(NULL);
+ }
+ }
+
+ private:
+ std::string name_;
+ int count_;
Mark Mentovai 2010/11/11 23:45:24 packy
dmac 2010/11/12 00:36:26 Done.
+ base::win::ScopedHandle event_;
+ DISALLOW_COPY_AND_ASSIGN(MultiProcessLockWin);
+};
+
+MultiProcessLock* MultiProcessLock::Create(const std::string &name) {
+ return new MultiProcessLockWin(name);
+}
« chrome/common/multi_process_lock_mac.cc ('K') | « chrome/common/multi_process_lock_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698