Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // Provide place to put profiling methods for the | |
| 6 // Lock class. | 5 // Lock class. |
| 7 // The Lock class is used everywhere, and hence any changes | |
| 8 // to lock.h tend to require a complete rebuild. To facilitate | |
| 9 // profiler development, all the profiling methods are listed | |
| 10 // here. | |
| 11 | 6 |
| 12 #include "base/lock.h" | 7 // Depricated file. See lock_impl_*.cc for platform specific versions. |
|
cpu_(ooo_6.6-7.5)
2008/10/21 22:41:23
Deprecated?
| |
| 13 #include "base/logging.h" | |
| 14 | |
| 15 #ifndef NDEBUG | |
| 16 Lock::Lock() | |
| 17 : lock_(), | |
| 18 recursion_count_shadow_(0), | |
| 19 recursion_used_(false), | |
| 20 acquisition_count_(0), | |
| 21 contention_count_(0) { | |
| 22 } | |
| 23 #else // NDEBUG | |
| 24 Lock::Lock() | |
| 25 : lock_() { | |
| 26 } | |
| 27 #endif // NDEBUG | |
| 28 | |
| 29 Lock::~Lock() { | |
| 30 } | |
| 31 | |
| 32 void Lock::Acquire() { | |
| 33 #ifdef NDEBUG | |
| 34 lock_.Lock(); | |
| 35 #else // NDEBUG | |
| 36 if (!lock_.Try()) { | |
| 37 // We have contention. | |
| 38 lock_.Lock(); | |
| 39 contention_count_++; | |
| 40 } | |
| 41 // ONLY access data after locking. | |
| 42 recursion_count_shadow_++; | |
| 43 acquisition_count_++; | |
| 44 if (2 == recursion_count_shadow_ && !recursion_used_) { | |
| 45 recursion_used_ = true; | |
| 46 // TODO(jar): this is causing failures in ThreadTest.Restart and | |
| 47 // ChromeThreadTest.Get on Linux. | |
| 48 // DCHECK(false); // Catch accidental redundant lock acquisition. | |
| 49 } | |
| 50 #endif // NDEBUG | |
| 51 } | |
| 52 | |
| 53 void Lock::Release() { | |
| 54 #ifndef NDEBUG | |
| 55 --recursion_count_shadow_; // ONLY access while lock is still held. | |
| 56 DCHECK(0 <= recursion_count_shadow_); | |
| 57 #endif // NDEBUG | |
| 58 lock_.Unlock(); | |
| 59 } | |
| 60 | |
| 61 bool Lock::Try() { | |
| 62 if (lock_.Try()) { | |
| 63 #ifndef NDEBUG | |
| 64 recursion_count_shadow_++; | |
| 65 acquisition_count_++; | |
| 66 if (2 == recursion_count_shadow_ && !recursion_used_) { | |
| 67 recursion_used_ = true; | |
| 68 DCHECK(false); // Catch accidental redundant lock acquisition. | |
| 69 } | |
| 70 #endif | |
| 71 return true; | |
| 72 } else { | |
| 73 return false; | |
| 74 } | |
| 75 } | |
| OLD | NEW |