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

Unified Diff: base/shared_mutex.h

Issue 4721001: Add multi_process_lock to chrome/common (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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: base/shared_mutex.h
diff --git a/base/shared_mutex.h b/base/shared_mutex.h
new file mode 100644
index 0000000000000000000000000000000000000000..6c01b5841105af053bdf133cff683fb582121205
--- /dev/null
+++ b/base/shared_mutex.h
@@ -0,0 +1,51 @@
+// 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.
+
+#ifndef BASE_SHARED_MUTEX_H_
+#define BASE_SHARED_MUTEX_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include <string>
Mark Mentovai 2010/11/09 17:43:14 System <headers> before project "headers."
dmac 2010/11/11 21:47:59 Done.
+
+#if OS_MACOSX
Mark Mentovai 2010/11/09 17:43:14 Nope - #if defined(OS_MACOSX).
dmac 2010/11/11 21:47:59 Done.
+#include <CoreFoundation/CoreFoundation.h>
+#elif OS_WIN
Mark Mentovai 2010/11/09 17:43:14 Same.
dmac 2010/11/11 21:47:59 Done.
+#include <windows.h>
+#endif
+
+namespace base {
+
+// Platform abstraction for a shared mutex between processes. The process
+// that owns the mutex lock will release it on exit even if exit is due
+// to a crash.
+// On Windows it is implemented as an event.
+// On Mac it is implemented using a CFMessagePort name.
+// On Linux it is implement using an abstract name port socket.
+class SharedMutex {
+ public:
+ SharedMutex(const std::string& name);
Mark Mentovai 2010/11/09 17:43:14 explicit.
dmac 2010/11/11 21:47:59 Done.
+ ~SharedMutex() { Unlock(); }
+
+ // Try to grab ownership of the mutex.
+ bool TryLock();
+
+ // Release ownership of the mutex.
+ void Unlock();
+
+ private:
+#if OS_WIN
Mark Mentovai 2010/11/09 17:43:14 #if defined(…) again.
dmac 2010/11/11 21:47:59 Done.
+ HANDLE event_;
sanjeevr 2010/11/09 06:21:05 We should use a ScopedHandle.
dmac 2010/11/11 21:47:59 Done.
+#elif OS_LINUX
+ int fd_;
+#elif OS_MACOSX
+ CFMessagePortRef port_;
TVL 2010/11/09 13:19:01 base::mac::ScopedCFTypeRef?
dmac 2010/11/11 21:47:59 Done.
+#endif
+ std::string name_;
+ DISALLOW_COPY_AND_ASSIGN(SharedMutex);
+};
+
+} // namespace base
+
+#endif // BASE_SHARED_MUTEX_H_
« no previous file with comments | « base/base.gypi ('k') | base/shared_mutex_linux.cc » ('j') | base/shared_mutex_linux.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698