diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-29 00:46:39 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-29 00:46:39 +0000 |
commit | e3b140eae1c14a6b76dedf0d5b7d9dd3c40af895 (patch) | |
tree | 73559388f92b8f998dcd2c2e3c34acd91df61d05 /base | |
parent | 5875dd0fca116e8205cf2b050e58ed0390f6d360 (diff) | |
download | chromium_src-e3b140eae1c14a6b76dedf0d5b7d9dd3c40af895.zip chromium_src-e3b140eae1c14a6b76dedf0d5b7d9dd3c40af895.tar.gz chromium_src-e3b140eae1c14a6b76dedf0d5b7d9dd3c40af895.tar.bz2 |
Temporary instrumentation to help understand lock errors on mac debug bots.
BUG=102161
Review URL: http://codereview.chromium.org/8414031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107835 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/synchronization/lock_impl.h | 23 | ||||
-rw-r--r-- | base/synchronization/lock_impl_posix.cc | 24 |
2 files changed, 47 insertions, 0 deletions
diff --git a/base/synchronization/lock_impl.h b/base/synchronization/lock_impl.h index 63efc5ff..1dcf6a4 100644 --- a/base/synchronization/lock_impl.h +++ b/base/synchronization/lock_impl.h @@ -17,6 +17,18 @@ #include "base/base_export.h" #include "base/basictypes.h" +#if defined(OS_MACOSX) && !defined(NDEBUG) +// For Mac debug builds, do some extra checks to make sure a LockImpl is not +// used after it has been freed. This instrumentation is to help track down +// spurious locking errors (EINVAL) which are happening on the bots. +// In particular, I want to make sure they aren't a consequence of having +// used a freed lock object (which can happen for instance when trying to +// post tasks to a destroyed MessageLoop). +// See http://crbug.com/102161 for more details. This instrumentation can be +// removed once that bug has been identified. +#define LOCK_IMPL_CHECK_LIVENESS +#endif + namespace base { namespace internal { @@ -53,6 +65,17 @@ class BASE_EXPORT LockImpl { #endif private: +#ifdef LOCK_IMPL_CHECK_LIVENESS + enum LivenessToken { + LT_ALIVE = 0xCa11ab1e, // 3390155550 + LT_DELETED = 0xDecea5ed, // 3738084845 + }; + + void CheckIsAlive(); + + LivenessToken liveness_token_; +#endif // LOCK_IMPL_CHECK_LIVENESS + OSLockType os_lock_; DISALLOW_COPY_AND_ASSIGN(LockImpl); diff --git a/base/synchronization/lock_impl_posix.cc b/base/synchronization/lock_impl_posix.cc index f638fcd..8db953a 100644 --- a/base/synchronization/lock_impl_posix.cc +++ b/base/synchronization/lock_impl_posix.cc @@ -12,6 +12,10 @@ namespace base { namespace internal { LockImpl::LockImpl() { +#ifdef LOCK_IMPL_CHECK_LIVENESS + liveness_token_ = LT_ALIVE; +#endif + #ifndef NDEBUG // In debug, setup attributes for lock error checking. pthread_mutexattr_t mta; @@ -30,25 +34,45 @@ LockImpl::LockImpl() { } LockImpl::~LockImpl() { +#ifdef LOCK_IMPL_CHECK_LIVENESS + CheckIsAlive(); + liveness_token_ = LT_DELETED; +#endif int rv = pthread_mutex_destroy(&os_lock_); DCHECK_EQ(rv, 0); } bool LockImpl::Try() { +#ifdef LOCK_IMPL_CHECK_LIVENESS + CheckIsAlive(); +#endif int rv = pthread_mutex_trylock(&os_lock_); DCHECK(rv == 0 || rv == EBUSY); return rv == 0; } void LockImpl::Lock() { +#ifdef LOCK_IMPL_CHECK_LIVENESS + CheckIsAlive(); +#endif int rv = pthread_mutex_lock(&os_lock_); DCHECK_EQ(rv, 0); } void LockImpl::Unlock() { +#ifdef LOCK_IMPL_CHECK_LIVENESS + CheckIsAlive(); +#endif int rv = pthread_mutex_unlock(&os_lock_); DCHECK_EQ(rv, 0); } +#ifdef LOCK_IMPL_CHECK_LIVENESS +void LockImpl::CheckIsAlive() { + CHECK_EQ(LT_ALIVE, liveness_token_) + << "Lock was invalid. Please see: http://crbug.com/102161"; +} +#endif + } // namespace internal } // namespace base |