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

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

Issue 292873002: make debug mode ~20% faster on linux (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win fix Created 6 years, 7 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
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
18 Lock::Lock() : lock_() { 16 Lock::Lock() : lock_() {
19 owned_by_thread_ = false;
20 owning_thread_id_ = kNoThreadId;
21 } 17 }
22 18
23 Lock::~Lock() { 19 Lock::~Lock() {
24 DCHECK(!owned_by_thread_); 20 DCHECK(owning_thread_ref_.is_null());
25 DCHECK_EQ(kNoThreadId, owning_thread_id_);
26 } 21 }
27 22
28 void Lock::AssertAcquired() const { 23 void Lock::AssertAcquired() const {
29 DCHECK(owned_by_thread_); 24 DCHECK(owning_thread_ref_ == PlatformThread::CurrentRef());
piman 2014/05/21 00:55:24 nit: DCHECK_EQ
hubbe 2014/05/21 04:27:35 DCHECK_EQ requires the values to be printable, Thr
30 DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId());
31 } 25 }
32 26
33 void Lock::CheckHeldAndUnmark() { 27 void Lock::CheckHeldAndUnmark() {
34 DCHECK(owned_by_thread_); 28 DCHECK(owning_thread_ref_ == PlatformThread::CurrentRef());
piman 2014/05/21 00:55:24 nit: DCHECK_EQ
hubbe 2014/05/21 04:27:35 See above.
35 DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId()); 29 owning_thread_ref_ = PlatformThreadRef();
36 owned_by_thread_ = false;
37 owning_thread_id_ = kNoThreadId;
38 } 30 }
39 31
40 void Lock::CheckUnheldAndMark() { 32 void Lock::CheckUnheldAndMark() {
41 DCHECK(!owned_by_thread_); 33 DCHECK(owning_thread_ref_.is_null());
42 owned_by_thread_ = true; 34 owning_thread_ref_ = PlatformThread::CurrentRef();
43 owning_thread_id_ = PlatformThread::CurrentId();
44 } 35 }
45 36
46 } // namespace base 37 } // namespace base
47 38
48 #endif // NDEBUG 39 #endif // NDEBUG
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698