summaryrefslogtreecommitdiffstats
path: root/base/lock_impl.h
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.h
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.h')
-rw-r--r--base/lock_impl.h33
1 files changed, 16 insertions, 17 deletions
diff --git a/base/lock_impl.h b/base/lock_impl.h
index 1c29075..d3fcc19 100644
--- a/base/lock_impl.h
+++ b/base/lock_impl.h
@@ -14,6 +14,7 @@
#endif
#include "base/basictypes.h"
+#include "base/platform_thread.h"
// This class implements the underlying platform-specific spin-lock mechanism
// used for the Lock class. Most users should not use LockImpl directly, but
@@ -40,10 +41,23 @@ class LockImpl {
// a successful call to Try, or a call to Lock.
void Unlock();
- // Return the native underlying lock.
+ // Debug-only method that will DCHECK() if the lock is not acquired by the
+ // current thread. In non-debug builds, no check is performed.
+ // Because linux and mac condition variables modify the underlyning lock
+ // through the os_lock() method, runtime assertions can not be done on those
+ // builds.
+#if defined(NDEBUG) || !defined(OS_WIN)
+ void AssertAcquired() {}
+#else
+ void AssertAcquired();
+#endif
+
+ // Return the native underlying lock. Not supported for Windows builds.
// TODO(awalker): refactor lock and condition variables so that this is
// unnecessary.
+#if !defined(OS_WIN)
OSLockType* os_lock() { return &os_lock_; }
+#endif
private:
OSLockType os_lock_;
@@ -51,6 +65,7 @@ class LockImpl {
#if !defined(NDEBUG) && defined(OS_WIN)
// All private data is implicitly protected by lock_.
// Be VERY careful to only access members under that lock.
+ PlatformThreadId owning_thread_id_;
int32 recursion_count_shadow_;
bool recursion_used_; // Allow debugging to continued after a DCHECK().
#endif // NDEBUG
@@ -58,21 +73,5 @@ class LockImpl {
DISALLOW_COPY_AND_ASSIGN(LockImpl);
};
-class AutoLockImpl {
- public:
- AutoLockImpl(LockImpl* lock_impl)
- : lock_impl_(lock_impl) {
- lock_impl_->Lock();
- }
-
- ~AutoLockImpl() {
- lock_impl_->Unlock();
- }
-
- private:
- DISALLOW_EVIL_CONSTRUCTORS(AutoLockImpl);
-
- LockImpl* lock_impl_;
-};
#endif // BASE_LOCK_IMPL_H_