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 <sys/types.h> 10#include <string> 11 12// Platform abstraction for a lock that can be shared between processes. 13// The process that owns the lock will release it on exit even if 14// the exit is due to a crash. Locks are not recursive. 15class MultiProcessLock { 16 public: 17 18 // The length of a multi-process lock name is limited on Linux, so 19 // it is limited it on all platforms for consistency. This length does 20 // not include a terminator. 21 static const size_t MULTI_PROCESS_LOCK_NAME_MAX_LEN = 106; 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_ 40