Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
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.
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.
9 #if !defined(NDEBUG)
11 #include "base/synchronization/lock.h"
12 #include "base/logging.h"
14 namespace base {
16 const PlatformThreadId kNoThreadId = static_cast<PlatformThreadId>(0);
18 Lock::Lock() : lock_() {
19 owned_by_thread_ = false;
20 owning_thread_id_ = kNoThreadId;
21 }
23 Lock::~Lock() {
24 DCHECK(!owned_by_thread_);
25 DCHECK_EQ(kNoThreadId, owning_thread_id_);
26 }
28 void Lock::AssertAcquired() const {
29 DCHECK(owned_by_thread_);
30 DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId());
31 }
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 }
40 void Lock::CheckUnheldAndMark() {
41 DCHECK(!owned_by_thread_);
42 owned_by_thread_ = true;
43 owning_thread_id_ = PlatformThread::CurrentId();
44 }
46 } // namespace base
48 #endif // NDEBUG