| 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 // This file is used for debugging assertion support. The Lock class | 5 // This file is used for debugging assertion support. The Lock class |
| 6 // is functionally a wrapper around the LockImpl class, so the only | 6 // is functionally a wrapper around the LockImpl class, so the only |
| 7 // real intelligence in the class is in the debugging logic. | 7 // real intelligence in the class is in the debugging logic. |
| 8 | 8 |
| 9 #include "base/threading/platform_thread.h" |
| 9 #if !defined(NDEBUG) | 10 #if !defined(NDEBUG) |
| 10 | 11 |
| 12 #include "base/logging.h" |
| 11 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 12 #include "base/logging.h" | |
| 13 | 14 |
| 14 namespace base { | 15 namespace base { |
| 15 | 16 |
| 16 Lock::Lock() : lock_() { | 17 Lock::Lock() : lock_() { |
| 17 owned_by_thread_ = false; | 18 owned_by_thread_ = false; |
| 18 owning_thread_id_ = static_cast<PlatformThreadId>(0); | 19 owning_thread_id_ = static_cast<PlatformThreadId>(0); |
| 19 } | 20 } |
| 20 | 21 |
| 21 void Lock::AssertAcquired() const { | 22 void Lock::AssertAcquired() const { |
| 22 DCHECK(owned_by_thread_); | 23 DCHECK(owned_by_thread_); |
| 23 DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId()); | 24 DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId()); |
| 24 } | 25 } |
| 25 | 26 |
| 26 void Lock::CheckHeldAndUnmark() { | 27 void Lock::CheckHeldAndUnmark() { |
| 27 DCHECK(owned_by_thread_); | 28 DCHECK(owned_by_thread_); |
| 28 DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId()); | 29 DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId()); |
| 29 owned_by_thread_ = false; | 30 owned_by_thread_ = false; |
| 30 owning_thread_id_ = static_cast<PlatformThreadId>(0); | 31 owning_thread_id_ = static_cast<PlatformThreadId>(0); |
| 31 } | 32 } |
| 32 | 33 |
| 33 void Lock::CheckUnheldAndMark() { | 34 void Lock::CheckUnheldAndMark() { |
| 34 DCHECK(!owned_by_thread_); | 35 DCHECK(!owned_by_thread_); |
| 35 owned_by_thread_ = true; | 36 owned_by_thread_ = true; |
| 36 owning_thread_id_ = PlatformThread::CurrentId(); | 37 owning_thread_id_ = PlatformThread::CurrentId(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 } // namespace base | 40 } // namespace base |
| 40 | 41 |
| 41 #endif // NDEBUG | 42 #endif // NDEBUG |
| OLD | NEW |