Chromium Code Reviews| 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" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 bool rv = lock_.Try(); | 54 bool rv = lock_.Try(); |
| 55 if (rv) { | 55 if (rv) { |
| 56 CheckUnheldAndMark(); | 56 CheckUnheldAndMark(); |
| 57 } | 57 } |
| 58 return rv; | 58 return rv; |
| 59 } | 59 } |
| 60 | 60 |
| 61 void AssertAcquired() const; | 61 void AssertAcquired() const; |
| 62 #endif // DCHECK_IS_ON() | 62 #endif // DCHECK_IS_ON() |
| 63 | 63 |
| 64 // Whether Lock mitigates priority inversion when used from different thread | |
|
robliao
2016/08/03 19:30:07
One more nit: Since we're generalizing this, I wou
fdoray
2016/08/03 19:32:10
Done.
| |
| 65 // priorities. Priority inversion is mitigated by allowing a thread that holds | |
| 66 // a Lock to run when higher priority threads try to acquire it. | |
|
gab
2016/08/03 19:36:25
I think the second sentence is specific to the imp
fdoray
2016/08/03 19:46:25
Done.
| |
| 67 static bool HandlesMultipleThreadPriorities() { | |
| 64 #if defined(OS_POSIX) | 68 #if defined(OS_POSIX) |
| 65 // Whether this platform has priority inheritance available. All locks will | |
| 66 // attempt to use the priority inheritance version if available. | |
| 67 static bool PriorityInheritanceAvailable() { | |
| 68 return internal::LockImpl::PriorityInheritanceAvailable(); | 69 return internal::LockImpl::PriorityInheritanceAvailable(); |
| 70 #elif defined(OS_WIN) | |
| 71 // Windows mitigates priority inversion by randomly boosting the priority of | |
| 72 // ready threads. | |
| 73 // https://msdn.microsoft.com/library/windows/desktop/ms684831.aspx | |
| 74 return true; | |
| 75 #else | |
| 76 #error Must specify if the lock handles multiple thread priorities. | |
|
gab
2016/08/03 19:36:25
#error Unsupported platform
is sufficient IMO
fdoray
2016/08/03 19:46:25
Done.
| |
| 77 #endif | |
| 69 } | 78 } |
| 70 #endif | |
| 71 | 79 |
| 72 #if defined(OS_POSIX) || defined(OS_WIN) | 80 #if defined(OS_POSIX) || defined(OS_WIN) |
| 73 // Both Windows and POSIX implementations of ConditionVariable need to be | 81 // Both Windows and POSIX implementations of ConditionVariable need to be |
| 74 // able to see our lock and tweak our debugging counters, as they release and | 82 // able to see our lock and tweak our debugging counters, as they release and |
| 75 // acquire locks inside of their condition variable APIs. | 83 // acquire locks inside of their condition variable APIs. |
| 76 friend class ConditionVariable; | 84 friend class ConditionVariable; |
| 77 #endif | 85 #endif |
| 78 | 86 |
| 79 private: | 87 private: |
| 80 #if DCHECK_IS_ON() | 88 #if DCHECK_IS_ON() |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 } | 143 } |
| 136 | 144 |
| 137 private: | 145 private: |
| 138 Lock& lock_; | 146 Lock& lock_; |
| 139 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); | 147 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); |
| 140 }; | 148 }; |
| 141 | 149 |
| 142 } // namespace base | 150 } // namespace base |
| 143 | 151 |
| 144 #endif // BASE_SYNCHRONIZATION_LOCK_H_ | 152 #endif // BASE_SYNCHRONIZATION_LOCK_H_ |
| OLD | NEW |