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

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: fix up silly linux compile issue 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) : name_(name) { }
14
15 virtual ~MultiProcessLockWin() {
16 if (event_.Get() != NULL) {
17 Unlock();
18 }
19 }
20
21 virtual bool TryLock() {
22 if (event_.Get() != NULL) {
23 DLOG(ERROR) << "MultiProcessLock is already locked - " << name_;
24 return true;
25 }
26 string16 wname = UTF8ToUTF16(name_);
27 HANDLE event = CreateEvent(NULL, FALSE, FALSE, wname.c_str());
sanjeevr 2010/11/12 17:47:56 Nit: You don't need to use a HANDLE here. You coul
dmac 2010/11/15 23:02:13 Fixed
28 if (event && GetLastError() != ERROR_ALREADY_EXISTS) {
29 event_.Set(event);
30 return true;
31 } else {
32 if (event) {
33 CloseHandle(event);
34 }
35 return false;
36 }
37 }
38
39 virtual void Unlock() {
40 if (event_.Get() == NULL) {
41 DLOG(ERROR) << "Over unlocked MultiProcessLock - " << name_;
42 return;
43 }
44 event_.Set(NULL);
45 }
46
47 private:
48 std::string name_;
49 base::win::ScopedHandle event_;
50 DISALLOW_COPY_AND_ASSIGN(MultiProcessLockWin);
51 };
52
53 MultiProcessLock* MultiProcessLock::Create(const std::string &name) {
54 return new MultiProcessLockWin(name);
55 }
OLDNEW
« chrome/common/multi_process_lock_unittest.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