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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/multi_process_lock.h"
6
7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h"
9 #include "base/win/scoped_handle.h"
10
11 class MultiProcessLockWin : public MultiProcessLock {
12 public:
13 explicit MultiProcessLockWin(const std::string& name)
14 : name_(name), count_(0) { }
15
16 virtual ~MultiProcessLockWin() {
17 if (count_ > 0) {
18 Unlock();
19 }
20 }
21
22 virtual bool TryLock() {
23 if (count_ > 0) {
24 count_ += 1;
25 return true;
26 }
27 string16 wname = UTF8ToUTF16(name_);
28 HANDLE event = CreateEvent(NULL, FALSE, FALSE, wname.c_str());
29 if (event && GetLastError() != ERROR_ALREADY_EXISTS) {
30 event_.Set(event);
31 count_ = 1;
32 return true;
33 } else {
34 if (event) {
35 CloseHandle(event);
36 }
37 return false;
38 }
39 }
40
41 virtual void Unlock() {
42 if (count_ == 0) {
43 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.
44 return;
45 }
46 count_ -= 1;
47 if (count_ == 0) {
48 event_.Set(NULL);
49 }
50 }
51
52 private:
53 std::string name_;
54 int count_;
Mark Mentovai 2010/11/11 23:45:24 packy
dmac 2010/11/12 00:36:26 Done.
55 base::win::ScopedHandle event_;
56 DISALLOW_COPY_AND_ASSIGN(MultiProcessLockWin);
57 };
58
59 MultiProcessLock* MultiProcessLock::Create(const std::string &name) {
60 return new MultiProcessLockWin(name);
61 }
OLDNEW
« 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