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

Unified Diff: chrome/common/multi_process_lock.h

Issue 4721001: Add multi_process_lock to chrome/common (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix up linux not compiling 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.h
diff --git a/chrome/common/multi_process_lock.h b/chrome/common/multi_process_lock.h
new file mode 100644
index 0000000000000000000000000000000000000000..de58a0ccc817b7659c8f7992631cabba54bb9e79
--- /dev/null
+++ b/chrome/common/multi_process_lock.h
@@ -0,0 +1,39 @@
+// 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 CHROME_COMMON_MULTI_PROCESS_LOCK_H_
+#define CHROME_COMMON_MULTI_PROCESS_LOCK_H_
+#pragma once
+
+#include <string>
+
+// Platform abstraction for a lock that can be shared between processes.
+// The process that owns the lock will release it on exit even if
+// the exit is due to a crash. Locks are not recursive.
+class MultiProcessLock {
+ public:
+
+ // The length of a multi process lock name is limited on Linux, so
Mark Mentovai 2010/11/15 23:42:55 Multiprocess is spelled without a space, but you c
dmac 2010/11/16 17:54:17 Done.
+ // it is limited it on all platforms for consistency. This length does
+ // not include a terminator. This is defined in terms of UNIX_PATH_MAX-2 on
Mark Mentovai 2010/11/15 23:42:55 You should have a COMPILE_ASSERT to guarantee this
dmac 2010/11/16 17:54:17 Done.
+ // Linux.
+ static const size_t MULTI_PROCESS_LOCK_NAME_MAX_LEN = 106;
Mark Mentovai 2010/11/15 23:42:55 You need to #include <sys/types.h> before you can
dmac 2010/11/16 17:54:17 Didn't seem to be needed on any platform, but adde
+
+ // Factory method for creating a multi process lock.
+ // |name| is the name of the lock. The name has special meaning on Windows
+ // where the prefix can determine the namespace of the lock.
+ // See http://msdn.microsoft.com/en-us/library/aa382954(v=VS.85).aspx for
+ // details.
+ static MultiProcessLock* Create(const std::string& name);
+
+ virtual ~MultiProcessLock() { }
+
+ // Try to grab ownership of the lock.
+ virtual bool TryLock() = 0;
+
+ // Release ownership of the lock.
+ virtual void Unlock() = 0;
+};
+
+#endif // CHROME_COMMON_MULTI_PROCESS_LOCK_H_

Powered by Google App Engine
This is Rietveld 408576698