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 | 12 |
12 namespace base { | 13 namespace base { |
13 namespace internal { | 14 namespace internal { |
14 | 15 |
15 LockImpl::LockImpl() { | 16 LockImpl::LockImpl() { |
16 #ifndef NDEBUG | 17 #ifndef NDEBUG |
17 // In debug, setup attributes for lock error checking. | 18 // In debug, setup attributes for lock error checking. |
18 pthread_mutexattr_t mta; | 19 pthread_mutexattr_t mta; |
19 int rv = pthread_mutexattr_init(&mta); | 20 int rv = pthread_mutexattr_init(&mta); |
(...skipping 15 matching lines...) Expand all Loading... |
35 DCHECK_EQ(rv, 0) << ". " << strerror(rv); | 36 DCHECK_EQ(rv, 0) << ". " << strerror(rv); |
36 } | 37 } |
37 | 38 |
38 bool LockImpl::Try() { | 39 bool LockImpl::Try() { |
39 int rv = pthread_mutex_trylock(&native_handle_); | 40 int rv = pthread_mutex_trylock(&native_handle_); |
40 DCHECK(rv == 0 || rv == EBUSY) << ". " << strerror(rv); | 41 DCHECK(rv == 0 || rv == EBUSY) << ". " << strerror(rv); |
41 return rv == 0; | 42 return rv == 0; |
42 } | 43 } |
43 | 44 |
44 void LockImpl::Lock() { | 45 void LockImpl::Lock() { |
| 46 base::debug::ScopedLockAcquireActivity lock_activity(this); |
45 int rv = pthread_mutex_lock(&native_handle_); | 47 int rv = pthread_mutex_lock(&native_handle_); |
46 DCHECK_EQ(rv, 0) << ". " << strerror(rv); | 48 DCHECK_EQ(rv, 0) << ". " << strerror(rv); |
47 } | 49 } |
48 | 50 |
49 void LockImpl::Unlock() { | 51 void LockImpl::Unlock() { |
50 int rv = pthread_mutex_unlock(&native_handle_); | 52 int rv = pthread_mutex_unlock(&native_handle_); |
51 DCHECK_EQ(rv, 0) << ". " << strerror(rv); | 53 DCHECK_EQ(rv, 0) << ". " << strerror(rv); |
52 } | 54 } |
53 | 55 |
54 } // namespace internal | 56 } // namespace internal |
55 } // namespace base | 57 } // namespace base |
OLD | NEW |