Index: base/synchronization/lock_impl_posix.cc |
=================================================================== |
--- base/synchronization/lock_impl_posix.cc (revision 107048) |
+++ base/synchronization/lock_impl_posix.cc (working copy) |
@@ -12,6 +12,10 @@ |
namespace internal { |
LockImpl::LockImpl() { |
+#if defined(OS_MAC) && !defined(NDEBUG) |
+ liveness_token_ = LT_ALIVE; |
+#endif |
+ |
#ifndef NDEBUG |
// In debug, setup attributes for lock error checking. |
pthread_mutexattr_t mta; |
@@ -30,25 +34,44 @@ |
} |
LockImpl::~LockImpl() { |
+#if defined(OS_MAC) && !defined(NDEBUG) |
+ CheckIsAlive(); |
+ liveness_token_ = LT_DELETED; |
+#endif |
int rv = pthread_mutex_destroy(&os_lock_); |
DCHECK_EQ(rv, 0); |
} |
bool LockImpl::Try() { |
+#if defined(OS_MAC) && !defined(NDEBUG) |
+ CheckIsAlive(); |
+#endif |
int rv = pthread_mutex_trylock(&os_lock_); |
DCHECK(rv == 0 || rv == EBUSY); |
return rv == 0; |
} |
void LockImpl::Lock() { |
+#if defined(OS_MAC) && !defined(NDEBUG) |
+ CheckIsAlive(); |
+#endif |
int rv = pthread_mutex_lock(&os_lock_); |
DCHECK_EQ(rv, 0); |
} |
void LockImpl::Unlock() { |
+#if defined(OS_MAC) && !defined(NDEBUG) |
+ CheckIsAlive(); |
+#endif |
int rv = pthread_mutex_unlock(&os_lock_); |
DCHECK_EQ(rv, 0); |
} |
+#if defined(OS_MAC) && !defined(NDEBUG) |
+bool LockImpl::CheckIsAlive() { |
+ CHECK_EQ(static_cast<uint32>(LT_ALIVE), liveness_token_); |
+} |
+#endif |
+ |
} // namespace internal |
} // namespace base |