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