michael@0: // Copyright (c) 2011 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: // This file is used for debugging assertion support. The Lock class michael@0: // is functionally a wrapper around the LockImpl class, so the only michael@0: // real intelligence in the class is in the debugging logic. michael@0: michael@0: #if !defined(NDEBUG) michael@0: michael@0: #include "base/synchronization/lock.h" michael@0: #include "base/logging.h" michael@0: michael@0: namespace base { michael@0: michael@0: const PlatformThreadId kNoThreadId = static_cast(0); michael@0: michael@0: Lock::Lock() : lock_() { michael@0: owned_by_thread_ = false; michael@0: owning_thread_id_ = kNoThreadId; michael@0: } michael@0: michael@0: Lock::~Lock() { michael@0: DCHECK(!owned_by_thread_); michael@0: DCHECK_EQ(kNoThreadId, owning_thread_id_); michael@0: } michael@0: michael@0: void Lock::AssertAcquired() const { michael@0: DCHECK(owned_by_thread_); michael@0: DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId()); michael@0: } michael@0: michael@0: void Lock::CheckHeldAndUnmark() { michael@0: DCHECK(owned_by_thread_); michael@0: DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId()); michael@0: owned_by_thread_ = false; michael@0: owning_thread_id_ = kNoThreadId; michael@0: } michael@0: michael@0: void Lock::CheckUnheldAndMark() { michael@0: DCHECK(!owned_by_thread_); michael@0: owned_by_thread_ = true; michael@0: owning_thread_id_ = PlatformThread::CurrentId(); michael@0: } michael@0: michael@0: } // namespace base michael@0: michael@0: #endif // NDEBUG