summaryrefslogtreecommitdiffstats
path: root/base/lock_impl_win.cc
diff options
context:
space:
mode:
authorralphl@chromium.org <ralphl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-18 23:46:27 +0000
committerralphl@chromium.org <ralphl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-18 23:46:27 +0000
commitc9d869c9d91ccb7ad8f061a93e7265bcddd85b47 (patch)
treef3731e31f3af7b8226fe76361c62d68d1c38478b /base/lock_impl_win.cc
parent5b65ba7172c2c29c0cfb2b66bb08178ce9652d4f (diff)
downloadchromium_src-c9d869c9d91ccb7ad8f061a93e7265bcddd85b47.zip
chromium_src-c9d869c9d91ccb7ad8f061a93e7265bcddd85b47.tar.gz
chromium_src-c9d869c9d91ccb7ad8f061a93e7265bcddd85b47.tar.bz2
Added a debug method AssertAcquired() that compiles to nothing in non-debug builds. In debug builds, the method will DCHECK if the
current thread does not hold the lock. I also removed a class that was not being used (AutoLockImpl) which seems like someone just copied the Lock.h file and blindly added an Impl for the AutoLock class. Thre are places in my code where I want to use the AutoUnlock class. I can't see why it was restricted to use by the condition variable class only, so I just made it into a regular class with no restrictions. I noticed that JamesR posted a CL about a month ago that made AutoUnlock a public class, but it was never committed, so I added him to this CL for review too. Review URL: http://codereview.chromium.org/48109 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12037 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/lock_impl_win.cc')
-rw-r--r--base/lock_impl_win.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/base/lock_impl_win.cc b/base/lock_impl_win.cc
index 8bb1943..503f105 100644
--- a/base/lock_impl_win.cc
+++ b/base/lock_impl_win.cc
@@ -13,6 +13,7 @@ LockImpl::LockImpl() {
#ifndef NDEBUG
recursion_count_shadow_ = 0;
recursion_used_ = false;
+ owning_thread_id_ = 0;
#endif // NDEBUG
// The second parameter is the spin count, for short-held locks it avoid the
// contending thread from going to sleep which helps performance greatly.
@@ -26,6 +27,9 @@ LockImpl::~LockImpl() {
bool LockImpl::Try() {
if (::TryEnterCriticalSection(&os_lock_) != FALSE) {
#ifndef NDEBUG
+ // ONLY access data after locking.
+ owning_thread_id_ = PlatformThread::CurrentId();
+ DCHECK_NE(owning_thread_id_, 0);
recursion_count_shadow_++;
if (2 == recursion_count_shadow_ && !recursion_used_) {
recursion_used_ = true;
@@ -41,6 +45,8 @@ void LockImpl::Lock() {
::EnterCriticalSection(&os_lock_);
#ifndef NDEBUG
// ONLY access data after locking.
+ owning_thread_id_ = PlatformThread::CurrentId();
+ DCHECK_NE(owning_thread_id_, 0);
recursion_count_shadow_++;
if (2 == recursion_count_shadow_ && !recursion_used_) {
recursion_used_ = true;
@@ -53,6 +59,15 @@ void LockImpl::Unlock() {
#ifndef NDEBUG
--recursion_count_shadow_; // ONLY access while lock is still held.
DCHECK(0 <= recursion_count_shadow_);
+ owning_thread_id_ = 0;
#endif // NDEBUG
::LeaveCriticalSection(&os_lock_);
}
+
+// In non-debug builds, this method is declared as an empty inline method.
+#ifndef NDEBUG
+void LockImpl::AssertAcquired() {
+ DCHECK(recursion_count_shadow_ > 0);
+ DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId());
+}
+#endif