Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: base/synchronization/lock.cc

Issue 13728003: Assert on deleting a held lock. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Assert on deleting a held lock. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/synchronization/lock.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #if !defined(NDEBUG) 9 #if !defined(NDEBUG)
10 10
11 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 13
14 namespace base { 14 namespace base {
15 15
16 const PlatformThreadId kNoThreadId = static_cast<PlatformThreadId>(0);
17
16 Lock::Lock() : lock_() { 18 Lock::Lock() : lock_() {
17 owned_by_thread_ = false; 19 owned_by_thread_ = false;
18 owning_thread_id_ = static_cast<PlatformThreadId>(0); 20 owning_thread_id_ = kNoThreadId;
21 }
22
23 Lock::~Lock() {
24 DCHECK(!owned_by_thread_);
25 DCHECK_EQ(kNoThreadId, owning_thread_id_);
26
27 // This may trip the assert on unlock in the owning thread.
willchan no longer on Chromium 2013/04/08 15:28:13 I don't understand this one. We know that it's fal
Sigurður Ásgeirsson 2013/04/08 15:32:35 Depends on whether the DCHECK is set to log fatall
28 owned_by_thread_ = false;
19 } 29 }
20 30
21 void Lock::AssertAcquired() const { 31 void Lock::AssertAcquired() const {
22 DCHECK(owned_by_thread_); 32 DCHECK(owned_by_thread_);
23 DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId()); 33 DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId());
24 } 34 }
25 35
26 void Lock::CheckHeldAndUnmark() { 36 void Lock::CheckHeldAndUnmark() {
27 DCHECK(owned_by_thread_); 37 DCHECK(owned_by_thread_);
28 DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId()); 38 DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId());
29 owned_by_thread_ = false; 39 owned_by_thread_ = false;
30 owning_thread_id_ = static_cast<PlatformThreadId>(0); 40 owning_thread_id_ = static_cast<PlatformThreadId>(0);
31 } 41 }
32 42
33 void Lock::CheckUnheldAndMark() { 43 void Lock::CheckUnheldAndMark() {
34 DCHECK(!owned_by_thread_); 44 DCHECK(!owned_by_thread_);
35 owned_by_thread_ = true; 45 owned_by_thread_ = true;
36 owning_thread_id_ = PlatformThread::CurrentId(); 46 owning_thread_id_ = PlatformThread::CurrentId();
37 } 47 }
38 48
39 } // namespace base 49 } // namespace base
40 50
41 #endif // NDEBUG 51 #endif // NDEBUG
OLDNEW
« no previous file with comments | « base/synchronization/lock.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698