Skip to content

Commit

Permalink
Add Lock::HandlesMultipleThreadPriorities().
Browse files Browse the repository at this point in the history
This static method is available on all platform. It replaces
Lock::PriorityInheritanceAvailable(). It will simplify code
that checks whether priority inversion will be mitigated when
Lock is used from different thread priorities.

E.g.:

  if (Lock::Lock::PriorityInheritanceAvailable())
    PlatformThread::SetCurrentThreadPriority(...);

Becomes:

  if (Lock::HandlesMultipleThreadPriorities())
    PlatformThread::SetCurrentThreadPriority(...);

BUG=611856

Review-Url: https://codereview.chromium.org/2206263002
Cr-Commit-Position: refs/heads/master@{#409890}
  • Loading branch information
fdoray authored and Commit bot committed Aug 4, 2016
1 parent 5fcccaf commit d84dc06
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions base/synchronization/lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,22 @@ class BASE_EXPORT Lock {
void AssertAcquired() const;
#endif // DCHECK_IS_ON()

// Whether Lock mitigates priority inversion when used from different thread
// priorities.
static bool HandlesMultipleThreadPriorities() {
#if defined(OS_POSIX)
// Whether this platform has priority inheritance available. All locks will
// attempt to use the priority inheritance version if available.
static bool PriorityInheritanceAvailable() {
// POSIX mitigates priority inversion by setting the priority of a thread
// holding a Lock to the maximum priority of any other thread waiting on it.
return internal::LockImpl::PriorityInheritanceAvailable();
}
#elif defined(OS_WIN)
// Windows mitigates priority inversion by randomly boosting the priority of
// ready threads.
// https://msdn.microsoft.com/library/windows/desktop/ms684831.aspx
return true;
#else
#error Unsupported platform
#endif
}

#if defined(OS_POSIX) || defined(OS_WIN)
// Both Windows and POSIX implementations of ConditionVariable need to be
Expand Down

0 comments on commit d84dc06

Please sign in to comment.