| 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 #include "base/synchronization/lock_impl.h" | 5 #include "base/synchronization/lock_impl.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "base/debug/activity_tracker.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 namespace internal { | 15 namespace internal { |
| 15 | 16 |
| 16 // Determines which platforms can consider using priority inheritance locks. Use | 17 // Determines which platforms can consider using priority inheritance locks. Use |
| 17 // this define for platform code that may not compile if priority inheritance | 18 // this define for platform code that may not compile if priority inheritance |
| 18 // locks aren't available. For this platform code, | 19 // locks aren't available. For this platform code, |
| 19 // PRIORITY_INHERITANCE_LOCKS_POSSIBLE() is a necessary but insufficient check. | 20 // PRIORITY_INHERITANCE_LOCKS_POSSIBLE() is a necessary but insufficient check. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 DCHECK_EQ(rv, 0) << ". " << strerror(rv); | 53 DCHECK_EQ(rv, 0) << ". " << strerror(rv); |
| 53 } | 54 } |
| 54 | 55 |
| 55 bool LockImpl::Try() { | 56 bool LockImpl::Try() { |
| 56 int rv = pthread_mutex_trylock(&native_handle_); | 57 int rv = pthread_mutex_trylock(&native_handle_); |
| 57 DCHECK(rv == 0 || rv == EBUSY) << ". " << strerror(rv); | 58 DCHECK(rv == 0 || rv == EBUSY) << ". " << strerror(rv); |
| 58 return rv == 0; | 59 return rv == 0; |
| 59 } | 60 } |
| 60 | 61 |
| 61 void LockImpl::Lock() { | 62 void LockImpl::Lock() { |
| 63 base::debug::ScopedLockAcquireActivity lock_activity(this); |
| 62 int rv = pthread_mutex_lock(&native_handle_); | 64 int rv = pthread_mutex_lock(&native_handle_); |
| 63 DCHECK_EQ(rv, 0) << ". " << strerror(rv); | 65 DCHECK_EQ(rv, 0) << ". " << strerror(rv); |
| 64 } | 66 } |
| 65 | 67 |
| 66 void LockImpl::Unlock() { | 68 void LockImpl::Unlock() { |
| 67 int rv = pthread_mutex_unlock(&native_handle_); | 69 int rv = pthread_mutex_unlock(&native_handle_); |
| 68 DCHECK_EQ(rv, 0) << ". " << strerror(rv); | 70 DCHECK_EQ(rv, 0) << ". " << strerror(rv); |
| 69 } | 71 } |
| 70 | 72 |
| 71 // static | 73 // static |
| (...skipping 15 matching lines...) Expand all Loading... |
| 87 // Fixed in glibc 2.17. | 89 // Fixed in glibc 2.17. |
| 88 // Priority inheritance mutexes may deadlock with condition variables | 90 // Priority inheritance mutexes may deadlock with condition variables |
| 89 // during recacquisition of the mutex after the condition variable is | 91 // during recacquisition of the mutex after the condition variable is |
| 90 // signalled. | 92 // signalled. |
| 91 return false; | 93 return false; |
| 92 #endif | 94 #endif |
| 93 } | 95 } |
| 94 | 96 |
| 95 } // namespace internal | 97 } // namespace internal |
| 96 } // namespace base | 98 } // namespace base |
| OLD | NEW |