summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-23 22:19:29 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-23 22:19:29 +0000
commitba198cae91c60d1e0a3a5119bb4c812a33febd96 (patch)
tree2e0747c394f2d4d5e38a885b45850ce0a774f045 /base
parentbe0c0050e6df6f18447fba2a85f2b9a7770e1955 (diff)
downloadchromium_src-ba198cae91c60d1e0a3a5119bb4c812a33febd96.zip
chromium_src-ba198cae91c60d1e0a3a5119bb4c812a33febd96.tar.gz
chromium_src-ba198cae91c60d1e0a3a5119bb4c812a33febd96.tar.bz2
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 Review URL: https://codereview.chromium.org/159283003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252864 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/synchronization/lock.cc40
-rw-r--r--base/synchronization/lock.h45
2 files changed, 45 insertions, 40 deletions
diff --git a/base/synchronization/lock.cc b/base/synchronization/lock.cc
index 49efbe9..6405b64 100644
--- a/base/synchronization/lock.cc
+++ b/base/synchronization/lock.cc
@@ -2,29 +2,54 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// 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());
@@ -42,7 +67,6 @@ 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 7e8ffe7..ab5ee68 100644
--- a/base/synchronization/lock.h
+++ b/base/synchronization/lock.h
@@ -16,47 +16,29 @@ 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() {
- lock_.Lock();
- CheckUnheldAndMark();
- }
- void Release() {
- CheckHeldAndUnmark();
- lock_.Unlock();
- }
+ void Acquire();
- bool Try() {
- bool rv = lock_.Try();
- if (rv) {
- CheckUnheldAndMark();
- }
- return rv;
- }
+ void Release();
+ // 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();
+
+#if !defined(NDEBUG)
void AssertAcquired() const;
-#endif // NDEBUG
+#else
+ void AssertAcquired() const {}
+#endif
+ 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
@@ -68,7 +50,6 @@ 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