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_H_ | 5 #ifndef BASE_SYNCHRONIZATION_LOCK_H_ |
6 #define BASE_SYNCHRONIZATION_LOCK_H_ | 6 #define BASE_SYNCHRONIZATION_LOCK_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/synchronization/lock_impl.h" | 11 #include "base/synchronization/lock_impl.h" |
12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 | 16 |
17 #if defined(OS_POSIX) | |
18 | |
19 // Determines which platforms can consider using priority inheritance locks. Use | |
danakj
2016/07/29 21:06:40
OK my only nit is that I rather this lives in lock
robliao
2016/07/29 21:22:53
sgtm. Moved and adjusted the comment for the more
| |
20 // this define for platform code that may not compile if priority inheritance | |
21 // locks aren't available. Lock::PriorityInheritanceAvailable still must be | |
22 // checked as the code may compile but the underlying platform still may not | |
23 // support priority inheritance locks. If you do not require the conditional | |
24 // inclusion at compile time, simply call Lock::PriorityInheritanceAvailable. | |
25 #if defined(OS_NACL) || defined(OS_ANDROID) | |
26 #define PRIORITY_INHERITANCE_LOCKS_POSSIBLE() 0 | |
27 #else | |
28 #define PRIORITY_INHERITANCE_LOCKS_POSSIBLE() 1 | |
29 #endif | |
30 | |
31 #endif | |
32 | |
17 // A convenient wrapper for an OS specific critical section. The only real | 33 // A convenient wrapper for an OS specific critical section. The only real |
18 // intelligence in this class is in debug mode for the support for the | 34 // intelligence in this class is in debug mode for the support for the |
19 // AssertAcquired() method. | 35 // AssertAcquired() method. |
20 class BASE_EXPORT Lock { | 36 class BASE_EXPORT Lock { |
21 public: | 37 public: |
22 #if !DCHECK_IS_ON() | 38 #if !DCHECK_IS_ON() |
23 // Optimized wrapper implementation | 39 // Optimized wrapper implementation |
24 Lock() : lock_() {} | 40 Lock() : lock_() {} |
25 ~Lock() {} | 41 ~Lock() {} |
26 void Acquire() { lock_.Lock(); } | 42 void Acquire() { lock_.Lock(); } |
(...skipping 27 matching lines...) Expand all Loading... | |
54 bool rv = lock_.Try(); | 70 bool rv = lock_.Try(); |
55 if (rv) { | 71 if (rv) { |
56 CheckUnheldAndMark(); | 72 CheckUnheldAndMark(); |
57 } | 73 } |
58 return rv; | 74 return rv; |
59 } | 75 } |
60 | 76 |
61 void AssertAcquired() const; | 77 void AssertAcquired() const; |
62 #endif // DCHECK_IS_ON() | 78 #endif // DCHECK_IS_ON() |
63 | 79 |
80 #if defined(OS_POSIX) | |
81 // Whether this platform has priority inheritance available. All locks will | |
82 // attempt to use the priority inheritance version if available. | |
83 static bool PriorityInheritanceAvailable() { | |
84 return internal::LockImpl::PriorityInheritanceAvailable(); | |
85 } | |
86 #endif | |
87 | |
64 #if defined(OS_POSIX) || defined(OS_WIN) | 88 #if defined(OS_POSIX) || defined(OS_WIN) |
65 // Both Windows and POSIX implementations of ConditionVariable need to be | 89 // Both Windows and POSIX implementations of ConditionVariable need to be |
66 // able to see our lock and tweak our debugging counters, as they release and | 90 // able to see our lock and tweak our debugging counters, as they release and |
67 // acquire locks inside of their condition variable APIs. | 91 // acquire locks inside of their condition variable APIs. |
68 friend class ConditionVariable; | 92 friend class ConditionVariable; |
69 #endif | 93 #endif |
70 | 94 |
71 private: | 95 private: |
72 #if DCHECK_IS_ON() | 96 #if DCHECK_IS_ON() |
73 // Members and routines taking care of locks assertions. | 97 // Members and routines taking care of locks assertions. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 } | 151 } |
128 | 152 |
129 private: | 153 private: |
130 Lock& lock_; | 154 Lock& lock_; |
131 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); | 155 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); |
132 }; | 156 }; |
133 | 157 |
134 } // namespace base | 158 } // namespace base |
135 | 159 |
136 #endif // BASE_SYNCHRONIZATION_LOCK_H_ | 160 #endif // BASE_SYNCHRONIZATION_LOCK_H_ |
OLD | NEW |