• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 
8 #include <sys/types.h>
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   // Factory method for creating a multi-process lock.
18   // |name| is the name of the lock. The name has special meaning on Windows
19   // where the prefix can determine the namespace of the lock.
20   // See http://msdn.microsoft.com/en-us/library/aa382954(v=VS.85).aspx for
21   // details.
22   static MultiProcessLock* Create(const std::string& name);
23 
~MultiProcessLock()24   virtual ~MultiProcessLock() { }
25 
26   // Try to grab ownership of the lock.
27   virtual bool TryLock() = 0;
28 
29   // Release ownership of the lock.
30   virtual void Unlock() = 0;
31 };
32 
33 #endif  // CHROME_COMMON_MULTI_PROCESS_LOCK_H_
34