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