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); |
+} |