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 BASE_SHARED_MUTEX_H_ | |
6 #define BASE_SHARED_MUTEX_H_ | |
7 #pragma once | |
8 | |
9 #include "base/basictypes.h" | |
10 #include <string> | |
Mark Mentovai
2010/11/09 17:43:14
System <headers> before project "headers."
dmac
2010/11/11 21:47:59
Done.
| |
11 | |
12 #if OS_MACOSX | |
Mark Mentovai
2010/11/09 17:43:14
Nope - #if defined(OS_MACOSX).
dmac
2010/11/11 21:47:59
Done.
| |
13 #include <CoreFoundation/CoreFoundation.h> | |
14 #elif OS_WIN | |
Mark Mentovai
2010/11/09 17:43:14
Same.
dmac
2010/11/11 21:47:59
Done.
| |
15 #include <windows.h> | |
16 #endif | |
17 | |
18 namespace base { | |
19 | |
20 // Platform abstraction for a shared mutex between processes. The process | |
21 // that owns the mutex lock will release it on exit even if exit is due | |
22 // to a crash. | |
23 // On Windows it is implemented as an event. | |
24 // On Mac it is implemented using a CFMessagePort name. | |
25 // On Linux it is implement using an abstract name port socket. | |
26 class SharedMutex { | |
27 public: | |
28 SharedMutex(const std::string& name); | |
Mark Mentovai
2010/11/09 17:43:14
explicit.
dmac
2010/11/11 21:47:59
Done.
| |
29 ~SharedMutex() { Unlock(); } | |
30 | |
31 // Try to grab ownership of the mutex. | |
32 bool TryLock(); | |
33 | |
34 // Release ownership of the mutex. | |
35 void Unlock(); | |
36 | |
37 private: | |
38 #if OS_WIN | |
Mark Mentovai
2010/11/09 17:43:14
#if defined(…) again.
dmac
2010/11/11 21:47:59
Done.
| |
39 HANDLE event_; | |
sanjeevr
2010/11/09 06:21:05
We should use a ScopedHandle.
dmac
2010/11/11 21:47:59
Done.
| |
40 #elif OS_LINUX | |
41 int fd_; | |
42 #elif OS_MACOSX | |
43 CFMessagePortRef port_; | |
TVL
2010/11/09 13:19:01
base::mac::ScopedCFTypeRef?
dmac
2010/11/11 21:47:59
Done.
| |
44 #endif | |
45 std::string name_; | |
46 DISALLOW_COPY_AND_ASSIGN(SharedMutex); | |
47 }; | |
48 | |
49 } // namespace base | |
50 | |
51 #endif // BASE_SHARED_MUTEX_H_ | |
OLD | NEW |