diff options
author | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-24 02:09:29 +0000 |
---|---|---|
committer | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-24 02:09:29 +0000 |
commit | 32f3c23a75143288e5c5eaa17fd53d2c224fb17c (patch) | |
tree | f1f5115b3ad4fa45c14fcb8dc69b045598d17474 | |
parent | f53c7ee18255d7f6da864b8a2829d08191d7e255 (diff) | |
download | chromium_src-32f3c23a75143288e5c5eaa17fd53d2c224fb17c.zip chromium_src-32f3c23a75143288e5c5eaa17fd53d2c224fb17c.tar.gz chromium_src-32f3c23a75143288e5c5eaa17fd53d2c224fb17c.tar.bz2 |
Revert of base: Cleanup: Simplify the declaration of Lock class. (https://codereview.chromium.org/159283003/)
Reason for revert:
This CL seems to cause DevToolsSanityTest.TestReattachAfterCrash to timeout
Original issue's description:
> base: Cleanup: Simplify the declaration of Lock class.
>
> This is the first step into merging Lock and LockImpl. The later will be
> merged into Lock when things get more clearer.
>
> BUG=283054
> TEST=base_unittests --gtest_filter=LockTest.*
> R=darin@chromium.org, brettw@chromium.org
>
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=252864
TBR=brettw@chromium.org,darin@chromium.org,tfarina@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=283054
Review URL: https://codereview.chromium.org/176793002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252869 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/synchronization/lock.cc | 40 | ||||
-rw-r--r-- | base/synchronization/lock.h | 45 |
2 files changed, 40 insertions, 45 deletions
diff --git a/base/synchronization/lock.cc b/base/synchronization/lock.cc index 6405b64..49efbe9 100644 --- a/base/synchronization/lock.cc +++ b/base/synchronization/lock.cc @@ -2,54 +2,29 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/synchronization/lock.h" +// This file is used for debugging assertion support. The Lock class +// is functionally a wrapper around the LockImpl class, so the only +// real intelligence in the class is in the debugging logic. + +#if !defined(NDEBUG) +#include "base/synchronization/lock.h" #include "base/logging.h" namespace base { -#if !defined(NDEBUG) const PlatformThreadId kNoThreadId = static_cast<PlatformThreadId>(0); -#endif Lock::Lock() : lock_() { -#if !defined(NDEBUG) owned_by_thread_ = false; owning_thread_id_ = kNoThreadId; -#endif } Lock::~Lock() { -#if !defined(NDEBUG) DCHECK(!owned_by_thread_); DCHECK_EQ(kNoThreadId, owning_thread_id_); -#endif } -void Lock::Acquire() { - lock_.Lock(); -#if !defined(NDEBUG) - CheckUnheldAndMark(); -#endif -} -void Lock::Release() { -#if !defined(NDEBUG) - CheckHeldAndUnmark(); -#endif - lock_.Unlock(); -} - -bool Lock::Try() { - bool rv = lock_.Try(); -#if !defined(NDEBUG) - if (rv) { - CheckUnheldAndMark(); - } -#endif - return rv; -} - -#if !defined(NDEBUG) void Lock::AssertAcquired() const { DCHECK(owned_by_thread_); DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId()); @@ -67,6 +42,7 @@ void Lock::CheckUnheldAndMark() { owned_by_thread_ = true; owning_thread_id_ = PlatformThread::CurrentId(); } -#endif } // namespace base + +#endif // NDEBUG diff --git a/base/synchronization/lock.h b/base/synchronization/lock.h index ab5ee68..7e8ffe7 100644 --- a/base/synchronization/lock.h +++ b/base/synchronization/lock.h @@ -16,29 +16,47 @@ namespace base { // AssertAcquired() method. class BASE_EXPORT Lock { public: +#if defined(NDEBUG) // Optimized wrapper implementation + Lock() : lock_() {} + ~Lock() {} + void Acquire() { lock_.Lock(); } + void Release() { lock_.Unlock(); } + + // If the lock is not held, take it and return true. If the lock is already + // held by another thread, immediately return false. This must not be called + // by a thread already holding the lock (what happens is undefined and an + // assertion may fail). + bool Try() { return lock_.Try(); } + + // Null implementation if not debug. + void AssertAcquired() const {} +#else Lock(); ~Lock(); // NOTE: Although windows critical sections support recursive locks, we do not // allow this, and we will commonly fire a DCHECK() if a thread attempts to // acquire the lock a second time (while already holding it). - void Acquire(); - - void Release(); + void Acquire() { + lock_.Lock(); + CheckUnheldAndMark(); + } + void Release() { + CheckHeldAndUnmark(); + lock_.Unlock(); + } - // If the lock is not held, take it and return true. If the lock is already - // held by another thread, immediately return false. This must not be called - // by a thread already holding the lock (what happens is undefined and an - // assertion may fail). - bool Try(); + bool Try() { + bool rv = lock_.Try(); + if (rv) { + CheckUnheldAndMark(); + } + return rv; + } -#if !defined(NDEBUG) void AssertAcquired() const; -#else - void AssertAcquired() const {} -#endif +#endif // NDEBUG - private: #if defined(OS_POSIX) // The posix implementation of ConditionVariable needs to be able // to see our lock and tweak our debugging counters, as it releases @@ -50,6 +68,7 @@ class BASE_EXPORT Lock { friend class WinVistaCondVar; #endif + private: #if !defined(NDEBUG) // Members and routines taking care of locks assertions. // Note that this checks for recursive locks and allows them |