Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: base/synchronization/lock.h

Issue 2206263002: Add Lock::HandlesMultipleThreadPriorities(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self-review Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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. Note that a
67 // low priority thread can still prevent high priority threads to run for an
68 // unbounded amount of time by holding a Lock.
gab 2016/08/03 18:47:25 Hmmm? Unbounded? The whole point here I thought wa
robliao 2016/08/03 19:17:15 It will be readied, but if it's doing a really lon
fdoray 2016/08/03 19:24:09 Done. Removed last sentence because it is true reg
69 static bool HandlesMultipleThreadPriorities() {
64 #if defined(OS_POSIX) 70 #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(); 71 return internal::LockImpl::PriorityInheritanceAvailable();
72 #elif defined(OS_WIN)
73 // Windows mitigates priority inversion by randomly boosting the priority of
74 // ready threads.
75 // https://msdn.microsoft.com/library/windows/desktop/ms684831.aspx
76 return true;
77 #else
78 #error "Unsupported platform"
gab 2016/08/03 18:47:25 nit: no indent for preprocessor commands
robliao 2016/08/03 19:17:15 Maybe "Unsupported platform. Must specify if the l
fdoray 2016/08/03 19:24:09 Done.
fdoray 2016/08/03 19:24:09 Done.
79 #endif
69 } 80 }
70 #endif
71 81
72 #if defined(OS_POSIX) || defined(OS_WIN) 82 #if defined(OS_POSIX) || defined(OS_WIN)
73 // Both Windows and POSIX implementations of ConditionVariable need to be 83 // 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 84 // able to see our lock and tweak our debugging counters, as they release and
75 // acquire locks inside of their condition variable APIs. 85 // acquire locks inside of their condition variable APIs.
76 friend class ConditionVariable; 86 friend class ConditionVariable;
77 #endif 87 #endif
78 88
79 private: 89 private:
80 #if DCHECK_IS_ON() 90 #if DCHECK_IS_ON()
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 145 }
136 146
137 private: 147 private:
138 Lock& lock_; 148 Lock& lock_;
139 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); 149 DISALLOW_COPY_AND_ASSIGN(AutoUnlock);
140 }; 150 };
141 151
142 } // namespace base 152 } // namespace base
143 153
144 #endif // BASE_SYNCHRONIZATION_LOCK_H_ 154 #endif // BASE_SYNCHRONIZATION_LOCK_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698