Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #ifndef CHROME_COMMON_MULTI_PROCESS_LOCK_H_ | |
| 6 #define CHROME_COMMON_MULTI_PROCESS_LOCK_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 // Platform abstraction for a lock that can be shared between processes. | |
| 12 // The process that owns the lock will release it on exit even if | |
| 13 // the exit is due to a crash. Locks are not recursive. | |
| 14 class MultiProcessLock { | |
| 15 public: | |
| 16 | |
| 17 // 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.
| |
| 18 // it is limited it on all platforms for consistency. This length does | |
| 19 // 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.
| |
| 20 // Linux. | |
| 21 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
| |
| 22 | |
| 23 // Factory method for creating a multi process lock. | |
| 24 // |name| is the name of the lock. The name has special meaning on Windows | |
| 25 // where the prefix can determine the namespace of the lock. | |
| 26 // See http://msdn.microsoft.com/en-us/library/aa382954(v=VS.85).aspx for | |
| 27 // details. | |
| 28 static MultiProcessLock* Create(const std::string& name); | |
| 29 | |
| 30 virtual ~MultiProcessLock() { } | |
| 31 | |
| 32 // Try to grab ownership of the lock. | |
| 33 virtual bool TryLock() = 0; | |
| 34 | |
| 35 // Release ownership of the lock. | |
| 36 virtual void Unlock() = 0; | |
| 37 }; | |
| 38 | |
| 39 #endif // CHROME_COMMON_MULTI_PROCESS_LOCK_H_ | |
| OLD | NEW |