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

Unified Diff: chrome/common/multi_process_lock_mac.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_mac.cc
diff --git a/chrome/common/multi_process_lock_mac.cc b/chrome/common/multi_process_lock_mac.cc
new file mode 100644
index 0000000000000000000000000000000000000000..653eadb077d736e750cac8a9ab95fe33fcbddd77
--- /dev/null
+++ b/chrome/common/multi_process_lock_mac.cc
@@ -0,0 +1,58 @@
+// 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/mac/scoped_cftyperef.h"
+#include "base/sys_string_conversions.h"
+
+class MultiProcessLockMac : public MultiProcessLock {
+ public:
+ explicit MultiProcessLockMac(const std::string& name)
+ : name_(name), count_(0) { }
Mark Mentovai 2010/11/11 23:45:24 Will this be accessed from multiple threads? If s
dmac 2010/11/12 00:36:26 Good point regarding multi threads. I got rid of t
+
Mark Mentovai 2010/11/11 23:45:24 OK, I just looked at your implementation on other
dmac 2010/11/12 00:36:26 Done.
+ virtual ~MultiProcessLockMac() {
+ if (count_ > 0) {
+ Unlock();
+ }
+ }
+
+ virtual bool TryLock() {
+ if (count_ > 0) {
+ count_ += 1;
+ return true;
+ }
+ CFStringRef cf_name(base::SysUTF8ToCFStringRef(name_));
+ base::mac::ScopedCFTypeRef<CFStringRef> scoped_cf_name(cf_name);
+ port_.reset(CFMessagePortCreateLocal(NULL, cf_name, NULL, NULL, NULL));
+ if (port_ != NULL) {
+ count_ = 1;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ virtual void Unlock() {
+ if (count_ == 0) {
+ DLOG(ERROR) << "Over unlocked MultiProcessLock " << name_;
Mark Mentovai 2010/11/11 23:45:24 I’d hyphenate this dude.
dmac 2010/11/12 00:36:26 Done.
+ return;
+ }
+ count_ -= 1;
+ if (count_ == 0) {
+ port_.reset();
+ }
+ }
+
+ private:
+ std::string name_;
+ int count_;
+ base::mac::ScopedCFTypeRef<CFMessagePortRef> port_;
Mark Mentovai 2010/11/11 23:45:24 Improve the struct packing. Put port_ before count
dmac 2010/11/12 00:36:26 Done.
+ DISALLOW_COPY_AND_ASSIGN(MultiProcessLockMac);
+};
+
+MultiProcessLock* MultiProcessLock::Create(const std::string &name) {
+ return new MultiProcessLockMac(name);
+}

Powered by Google App Engine
This is Rietveld 408576698