OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_SYNCHRONIZATION_LOCK_IMPL_H_ | 5 #ifndef BASE_SYNCHRONIZATION_LOCK_IMPL_H_ |
6 #define BASE_SYNCHRONIZATION_LOCK_IMPL_H_ | 6 #define BASE_SYNCHRONIZATION_LOCK_IMPL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
12 #include <windows.h> | 12 #include <windows.h> |
13 #elif defined(OS_POSIX) | 13 #elif defined(OS_POSIX) |
14 #include <pthread.h> | 14 #include <pthread.h> |
15 #endif | 15 #endif |
16 | 16 |
17 #include "base/base_export.h" | 17 #include "base/base_export.h" |
18 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
19 | 19 |
| 20 #if defined(OS_MACOSX) && !defined(NDEBUG) |
| 21 // For Mac debug builds, do some extra checks to make sure a LockImpl is not |
| 22 // used after it has been freed. This instrumentation is to help track down |
| 23 // spurious locking errors (EINVAL) which are happening on the bots. |
| 24 // In particular, I want to make sure they aren't a consequence of having |
| 25 // used a freed lock object (which can happen for instance when trying to |
| 26 // post tasks to a destroyed MessageLoop). |
| 27 // See http://crbug.com/102161 for more details. This instrumentation can be |
| 28 // removed once that bug has been identified. |
| 29 #define LOCK_IMPL_CHECK_LIVENESS |
| 30 #endif |
| 31 |
20 namespace base { | 32 namespace base { |
21 namespace internal { | 33 namespace internal { |
22 | 34 |
23 // This class implements the underlying platform-specific spin-lock mechanism | 35 // This class implements the underlying platform-specific spin-lock mechanism |
24 // used for the Lock class. Most users should not use LockImpl directly, but | 36 // used for the Lock class. Most users should not use LockImpl directly, but |
25 // should instead use Lock. | 37 // should instead use Lock. |
26 class BASE_EXPORT LockImpl { | 38 class BASE_EXPORT LockImpl { |
27 public: | 39 public: |
28 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
29 typedef CRITICAL_SECTION OSLockType; | 41 typedef CRITICAL_SECTION OSLockType; |
(...skipping 16 matching lines...) Expand all Loading... |
46 void Unlock(); | 58 void Unlock(); |
47 | 59 |
48 // Return the native underlying lock. Not supported for Windows builds. | 60 // Return the native underlying lock. Not supported for Windows builds. |
49 // TODO(awalker): refactor lock and condition variables so that this is | 61 // TODO(awalker): refactor lock and condition variables so that this is |
50 // unnecessary. | 62 // unnecessary. |
51 #if !defined(OS_WIN) | 63 #if !defined(OS_WIN) |
52 OSLockType* os_lock() { return &os_lock_; } | 64 OSLockType* os_lock() { return &os_lock_; } |
53 #endif | 65 #endif |
54 | 66 |
55 private: | 67 private: |
| 68 #ifdef LOCK_IMPL_CHECK_LIVENESS |
| 69 enum LivenessToken { |
| 70 LT_ALIVE = 0xCa11ab1e, // 3390155550 |
| 71 LT_DELETED = 0xDecea5ed, // 3738084845 |
| 72 }; |
| 73 |
| 74 void CheckIsAlive(); |
| 75 |
| 76 LivenessToken liveness_token_; |
| 77 #endif // LOCK_IMPL_CHECK_LIVENESS |
| 78 |
56 OSLockType os_lock_; | 79 OSLockType os_lock_; |
57 | 80 |
58 DISALLOW_COPY_AND_ASSIGN(LockImpl); | 81 DISALLOW_COPY_AND_ASSIGN(LockImpl); |
59 }; | 82 }; |
60 | 83 |
61 } // namespace internal | 84 } // namespace internal |
62 } // namespace base | 85 } // namespace base |
63 | 86 |
64 #endif // BASE_SYNCHRONIZATION_LOCK_IMPL_H_ | 87 #endif // BASE_SYNCHRONIZATION_LOCK_IMPL_H_ |
OLD | NEW |