summaryrefslogtreecommitdiffstats
path: root/base/synchronization/lock.cc
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/synchronization/lock.cc
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/synchronization/lock.cc')
-rw-r--r--base/synchronization/lock.cc40
1 files changed, 32 insertions, 8 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